From the Super Mario Wiki
Buttons are objects in Mario & Luigi: Superstar Saga. They are found throughout the Beanbean Kingdom, and are used as switches for various purposes. Usually, this involves opening nearby gates, doors, or other barriers, though Buttons can also affect other elements in the environment. They can only be pressed with Mario or Luigi's hammer. Occasionally a Button is too high to reach normally, and requires Luigi to enter a barrel using his Luigi Dunk so that Mario can jump on him and hit the Button.