In order to get this star, you will want to have unlocked the Metal Cap. Once you do, take the left path at the beginning of the course and make it through the Black Hole area. When you get to the door past the boulders, use the elevator beyond it to return to the Underground Lake area. When the elevator reaches the bottom, you should see a Metal Cap box right there, which will be key to getting this star. Before you don the Metal Cap, check out the surroundings first to know what you’re getting to exactly.
The path to the water as a darker brown coloring for an actual path, which extends underwater and leads to the purple switch that is slightly submerged by the metal grates blocking a door. So, you will need to put on the Metal Cap and quickly navigate this path to the switch, which will move the metal grates and allow access to the door. You do not have much time for this, though, as the Metal Cap will reach the end of its duration around the same time as when you get to the switch. Thankfully, if you don’t make it in time, you have the chance to keep trying until you get it right. Once you do, go through the door and perform the necessary Long Jumps to reach the star at the end.
There is another method of hitting the switch that doesn’t involve using the Metal Cap. Go to the switch and look at the signpost near it, positioning Mario to the right of it. Try to turn the camera so you’re looking in the direction of the switch. What you will want to do is perform a Triple Jump and at the peak of it, dive forward to land in the vicinity of the switch. The force of the jump and dive should give you enough momentum to hit the switch. Remember to not gain too much forward momentum on the Triple Jump, plus you can hold back on the left stick a little bit when you perform the dive.