This seems to me an interesting question, with variants in many contexts, whose answer is not self-evident.
The notation $(A = B)^2$ should be considered problematic because it is undefined (another way of saying "nonstandard") in the same sense as undefined behavior in a programming language is undefined - it might compile, it might be interpreted properly, but there is no guarantee that it will be understood. Mathematical syntax functions as a shorthand for indicating to who reads it what operations were performed or should be performed to pass from one statement to the next. It works best when the translation is straightforward (when correctly done).
A square amounts to multiplying something by itself and generally for this to make sense one has to operate within some mathematical framework (algebraic structure) in which multiplications are defined - one needs some sort of binary operation on the set of things that can be multiplied. What is the square of an equality? Usually one considers an equality as having a truth value - $0$ or something nonzero - and in fact it makes sense to square a truth value - in a programming language such as C code of the form $(A == B)*(A == B)$ is syntactically correct and would have a value equal to $0$ if $A$ and $B$ are unequal and something nonzero (usually $1$, but in principle dependent on the compiler) in the case $A$ and $B$ are equal. However, note that, although coherent, this way of interpreting $(A = B)^2$ is not what the student has in mind in this case! The problem is that the correspondence between the notation $\,^2$ and the operations to be performed is not the usual one indicated by an exponent.
The student has in mind to indicate notationally the following reasoning: Since $A$ equals $B$, $A^{2}$ equals $B^{2}$. It captures far better the sense of the reasoning to write
$$ A = B \implies A^{2}= B^{2}$$
than to write $(A = B)^{2}$. Often students are taught to write simply
$$A = B\\
A^{2}= B^{2}$$
with no symbol indicating logical implication, such implication being indicated by passing from one line to the next. (Since the implication is left implicit many students do not realize it is there. Such a student thinks of a pattern of operations, rather than a series of implications.)
Summary: what is problematic about writing $(A = B)^2$ is that the exponent does not correspond directly to squaring something in the sense of multiplying something by itself. Rather it is something that has to be unpacked and interpreted (like the notation for a line integral) if it is to be evaluated - and, moreover, there already exists a more easily and more directly interpretable notation for indicating the same operations.
One encounters things like this in many contexts. In linear algebra one sees often identification of $1 \times n$ row vectors, $n \times 1$ column vectors, and elements of $\mathbb{R}^{n}$. Many a successful engineer/physicist makes such identifications regularly, yet making such identifications usually indicates that someone does not distinguish well between equality and isomorphism. When teaching a class where it matters to understand this distinction, I generally start out by advising students about the incorrectness of identifying two things that are not equal, marking it but not taking off points, but later in the semester, when the error is repeated, I take points off (it is never a substantial deduction, usually only a marginal one). The experience is that students who don't eventually manage to understand the distinction between equating and identifying rows and columns have trouble with many other aspects of the course, so that insisting on such a trivial point is not as formal as it may appear to some.
Another similar example from linear algebra: one calculates ranks and determinants by applying elementary row (and, for determinants, column) operations. In the case of rank computations the matrices produced are (tautologically) equivalent via row operations but not equal, while in the case of determinants there results a string of equalities. Many students write $=$ in both cases, and this usually signals conceptual deficits that are fairly serious in the context of learning linear algebra. Such students are generally memorizing sequences of operations and have very little understanding of what those operations are doing (e.g. that row operations correspond to operations on equations), or why they are being performed (e.g. eliminating redundancies/dependencies). One understands what such a student is doing, such a student might very well obtain the correct answer to the particular formal exercise being solved, but such a student almost always does not understand what he/she is doing.
Writing $(A = B)^2$ in place of $A^2 = B^2$ seems to me somewhere in between these two examples and how to react to it depends on the context in which it appears. Objecting to it is less fussy than objecting to identifying row and column vectors, but the possible conceptual problem underlying it is not so severe as in the case of writing $=$ between matrices related by row operations. My approach would be to mark it in red and explain in detail what should be written, but to take off no points (since in this case it seems the student did compute correctly, just used nonstandard notation to communicate the computations). If the nonstandard notation is used repeatedly, I would probably progress at some point to taking off points. I say "probably" because exactly how to react surely depends on the context (the student, the class, the goals of the class, etc.). (If a university student writes this it is an indicator of low probability of success in university level math classes, but when written by a 10 year old it could even be an indicator of an autonomous and active mind - inventing reasonable notation is not so trivial).