It's a quirk of the original implementation of the message signing logic which was introduced in Bitcoin Core in 2011.
When the message is signed, it must be serialized before it is hashed. The serialize methods in Bitcoin Core are shared between the network, hash preimage, file, etc. serializations, most of which require that the data be prepended with a compact size uint that specifies the length of the data. Thus those methods will prepend such a compact size uint when serializing whatever data.
The implementation of the message signing logic used those same serialization methods in order to produce the preimage that would be hashed. Thus the strings must be prepended with their lengths for the hash preimage.