It’s not a wardrobe malfunction in the traditional sense, but still a part of his swimming attire which is worn to reduce drag.
Phelps’ swimming cap broke right seconds before he was set to dive in. Realizing he had just a little time to rectify the situation after looking at the scoreboard, he called out to teammate Connor Dwyer, who'd already swum, and asked for his cap.
This minor mishap didn't stop the US team from taking the Gold home.