Transformer decoder output - how is it linear?
I'm not quite sure how's the decoder output is flattened into a single vector


That's the thing. It isn't flattened into a single vector. The linear transformation is applied to all $M$ vectors in the sequence individually. These vectors have a fixed dimension, which is why it works.