Answer: The Shulchan Aruch (OC 308:4) writes that one is allowed to move kisvei kodesh, holy writings, on Shabbos, though the Rema adds that tefillin are muktze. The Magen Avraham (OC 308:11), however, writes that one may move tefillin to protect them if they are in the way (gufo umekomo). While tefillin are expensive and have a very specific purpose, R’ Yehoshua Neuwirth (Shemiras Shabbos Kehilchasa 20:n32) explains that they are categorized as muktze machmas issur (items with a prohibited use) rather than muktze machmas chisaron kis (valuable items which cannot be moved even for such reasons).
The Magen Avraham (OC 308:19) and Mishna Berura (308:35) write that a door that fell off is muktze. R’ Neuwirth quotes R’ Shmuel Burstein (Minchas Shabbos 88:38) who compares this to a mezuza that fell, and writes, therefore, that one mustn’t move it unless it is in a place where it may be trampled on, etc.
R’ Moshe Stern (Baer Moshe 8:72) however, disagrees, writing that mezuzos are not muktze. The Mishna Berura (307:63) allows one to read a get on Shabbos as one can learn from it. Likewise, mezuzos are not muktze and may be handled on Shabbos as one can read the shema and learn from them.
R’ Eliezer Waldenberg (Tzitz Eliezer 13:53) quotes the Sedei Chemed (4:115) who writes that there is a machlokes as to whether one can even return a mezuza that fell on Shabbos to its case as there are poskim that hold that one mustn’t live in a house without a mezuza. Similar to tovelling a new dish on Shabbos, replacing the mezuza is a form of tikkun kli, fixing something, and therefore prohibited.
R’ Waldenberg and R’ Shmuel Wosner (Shevet Halevi 4:143) write, however, that there is no issue in replacing the mezuza in such a manner. One msutn’t, however, reattach a mezuza with a nail on Shabbos as this is akin to boneh, building (Rivevos Ephraim 2:29:10).
In conclusion, while one can’t affix a mezuza case on Shabbos, one may replace a mezuza that fell out of its case.