There is no hard and fast rule for when we choose brevity over formal correctness, any more than there are hard and fast rules for when to use pronouns (he,she,they,it) rather than a specific name for the item or person at hand. If there is any rule, it is “Do so when it won’t cause confusion and it feels redundant to repeat it.” All shorthand is to make communication less noisy, and all shorthand risks confusion.
Formally, it is wrong. But almost all of our math talk is formally wrong in some way. We make discussion less noisy and easier to understand by eliminating duplicate information.
Here, we clearly are talking about the question at hand, so there is only one possible meaning we could have for for $a\equiv b.$ Here, these lines are long enough without tacking on a redundant $\pmod{18}.$ Each answer would require more than $1$ line, or smaller handwriting.
Also, if $a^2\equiv b^2\pmod n, $ it is not true, in general, that $a\equiv b\pmod n.$
There are examples where we use notation even where it is not technically required.
For example, we assume all numbers we encounter are written in base $10$ unless a base is specified.
But in a question that requires multiple bases, you will often write $13_{10}$ rather than just $13,$ even though you technically don’t need to say it, because your reader might wonder if you forgot to specify, and meant $13_7.$