Can a person leave the masjid to take a shower at home to get rid of the sweat and to change clothes?

Find answers

Yes, especially if the masjid does not have a washing facility.

It was narrated from A’isha (ra): “The Messenger of Allah (pbuh) used to put his head out of the masjid while he was performing i’tikaf, and I would wash it, while I was menstruating.” [Sunan an-Nasa’i]