It's going to depend in part on local laws in addition to whatever policy the hotel has. For example, in Italy
Under Italian public security legislation, guests must register upon arrival at the hotel and their personal details (including passports or other IDs) must be communicated to the local police authorities within 24 hours.
In the Ukraine
At the time a guest registers for a room, the guest must fill out a guest registration form and provide an internal passport or other relevant document if the guest is a Ukrainian citizen, or a national passport and visa (unless otherwise provided by a bilateral treaty) permitting stay in Ukraine, if the guest is a citizen of a foreign country.
In the UK
The hotel must keep a record of the full name and nationality of its guests over 16 years of age. For guests who are not citizens of the UK or the Commonwealth, the hotel must also make a record of their passport number, place of issue of their passport and their next destination including the address if possible.
In some places it's to verify your identity, but in some hotels in the US it's not that uncommon for them to take the ID, bring it below the counter to pretend to hold it under the bright light to read it, but they actually scan it to collect the information on it. No clue as to the purpose of that.