From the Super Mario Wiki
Gold Blocks are golden Brick Blocks that appear in New Super Mario Bros. 2. They appear when Mario or Luigi hit a Coin Block at least 10 times. When this happens, Mario or Luigi can wear the Gold Block over his head, thus producing coins from it if he keeps moving, making it very similar in function to the Coin Boxes from Super Mario 3D Land. If Mario or Luigi runs fast enough, the amount of coins produced from the block increases. When a Gold Block is worn, the face side of it resembles Mario/Luigi's face, as shown in the image below. The Gold Block disappears after 100 coins have been collected from it, or if Mario or Luigi is hit while wearing it. While playing in co-op mode, if a player ground pounds on another player wearing a Gold Block, they will lose the Gold Block as well. If Mario/Luigi grabs the Goal Pole while still wearing the Gold Block, he can continue to get coins from going down the pole and jumping off of it, finally losing it after landing on the ground. Hitting one from either side, from above, or while wearing another Gold Block causes 50 coins to spout out of the top before it disappears. The Gold Block will also protect against the stone spell used by the Koopalings in World 6 and World Star, though only once.
Flying Gold Blocks also appear in the game and are seen flying around in their idle golden forms, since there are no flying Coin Blocks. They occasionally appear for every 200,000 points earned and fly above Mario on the world map, and can be used right away upon entering a level, similar to the red Flying ? Blocks in the first New Super Mario Bros.. Also, when the score reach the maximum of 999,999,999 points, Flying Gold Blocks will always appear no matter how many points Mario earns.