Is it permissible for someone to take a carpet or anything else from a Masjid (mosque) by accident or otherwise and replace it with something better?
This is not permissible, as the carpet is a Waqf (endowment) for the Masjid, and it is not Halal (lawful) for you to dispose of it, even if it does appear to be beneficial to do so. You should coordinate this with the relevant authorities in the Masjid who would follow the Shar‘y (Islamically lawful) procedure. (Part No. 16; Page No. 86) May Allah grant us success. May peace and blessings be upon our Prophet, his family, and Companions.