It is called 'Dressing Ship'. It is a tradition... even back to the age of sail, mostly RN though.
I think the only time you will find a RN ship dressed at sea is when the ship is escorting the Royal Yacht. Some of you might remember when we did have a Royal yacht!
The flags used are not just colourful 'bunting'. Signal flags are used, but are never hung in such a sequence that there is any kind of message. My first trip to sea in FRANCONIA back in 1967 I spend a few days with the Deck Storekeeper making up a set of dress ship flags. The flags were arranged... two square 'alphabet flags followed by a numerical flag or pennant. They were laid out first so that there were not too many of any particular colour grouped together. The hoist of each flag was carefully spliced into a length of 1/4 inch dia. FSWR.