The Vatican is a self-governing city-state that serves as the seat of the Roman Catholic Church. The Vatican has dress regulations throughout the city because it is a religious state.
They advocate modest clothing and skin covering as a religious institution, similar to how other religions have tenets dictating appropriate attire. The guards have the right to refuse you access into the city and its attractions if you do not follow the dress code and are dressed immodestly.