The Rambam talks about dancing on Sukkos and other types of Simcha Shel Mitzva. Why did the Rambam feel it is so important to mention the story of Dovid HaMelech, who danced in front of the Torah in a way that his wife Michal felt was extremely lacking in dignity?
The Rambam is teaching us to be like Dovid, and not to care about our Kavod when dancing for Hashem. Dovid told Michal that the reason why he became king while her father Shaul could not remain king, was because he didn't care about his Kavod, whereas Shaul did.
The Chovos Halvavos in Shaar HaBitachon constantly explains Bitachon as relying only on Hashem vs. not relying on people.
The stories about Dovid are unbelievable. He is constantly being attacked and hurt by the very people that everyone relies upon. His siblings wanted him dead. His father-in-law Shaul [whose life he saved] tried to kill him. His sons rebelled against him. His Rebbe, Achitofel went against him. Chazal say that his right-hand man [and general] Yoav was really against him, although he seemed like his supporter.
Even his wife Michal [whom he loved especially] was Mʼzalzel in Dovid because of the dancing episode. And of course, Klal Yisroel his nation betrayed him many times by siding with his enemies! We can say that since Dovid is our king and our prime example in Middas HaBitachon in Hashem, he needed to have a life devoid of Kavod, with no one to rely upon except Hashem.
The entire idea of dancing before Hashem, is to show our Simcha in having Bitachon [and relying] ONLY ON HASHEM and not in people [or anything].