Remember seeing or hearing this too.
Legend has it, that it goes back to Cardiff changing them in 1927 to commemorate their FA cup win, but also to annoy and remind local rivals Swansea that they won it. And it was picked up from there.
Nothing official in the rules about it.
Before corner flags were implented there was a system known as rouges, where two flags were placed 4 yards from the goal post on either side, if the ball went between them or was touched down or something the attacking team got a point. The number of these rouges was used to determine a winner in a tied game.