There could be a problem with the linear layer after the attention inside a transformer?
No, this is not a problem.
If we zoom into the scaled dot product attention blocks, which happen before the projection with $W^O$ we see this:

There, you can see how the masking of the current and future positions happens inside the scaled dot product attention, which happens before the multiplication by $W^O$. Therefore, the values learned for $W^O$ are trained only with the information from the previous tokens in the decoder.