Layer normalization rescales values across the features of a single example rather than across a batch, which is why transformers use it instead of batch normalization.
Batch normalization uses statistics across the batch and depends on batch size. Layer normalization uses one example, which is why transformers use it.
Layer normalization rescales values using the statistics of a single example, computed across its features. Unlike batch normalization, it does not look at other examples at all.
That independence is why transformers use it. Sequences vary in length and batches vary in size, and layer normalization behaves identically regardless, including on a batch of one.
Think of it like this. Think of grading each student against their own average across subjects, rather than against the class. It works the same whether the class has thirty students or one.