From the Super Mario Wiki
Laser Blocks are blocks that appear in Mario & Luigi: Partners in Time. There are two varieties, though they look the same. Each Laser Block is pink and has a red star in the center.
The Laser Blocks in the Star Shrine emit two differently colored lasers when hit. However, these lasers only make up half of a complete laser beam. There are five Laser Blocks and five differently colored lasers. Mario, Luigi, Baby Mario, and Baby Luigi must connect all five laser beams in order to gain entrance to the main area of the Star Shrine.
The Laser Blocks in Peach's Castle in the past are used to defeat a Chain Chomp. There are four of them, and striking any two will create a laser that fires in a position relative to the position of the blocks. The goal is to strike the right Laser Blocks to hit the Chomp hiding in pipes above them.