system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Where did the ongoing ‘do a good deed and the mayor of the town congratulates you with the key to the city’ in movies & shows come from? Was that ever a real thing?

I’m watching family guy & Peter found a missing kid and as a reward the mayor gave him the key to the city (or town hall?). 
I’ve also seen this happen in a few other movies. 

Was this ever a real thing? Is this an inside joke I’m not aware of?
gpt
The "key to the city" comes from serfdom, where it was originally called the "freedom of the city," meaning that the honored person was to be treated as a free person, not a serf, while they were in the city. The "key to the city" derives from the custom of walled cities closing and locking their gates up at night; if you wanted to enter, you'd either have to wait until morning or convince a guard that you had an important enough reason to open the gates. However, if you have a "key" to the gates, that meant that you could open them whenever you wished; you had the freedom to enter/exit the city as you desired. Hence, the "key to the city" phrase replaced "freedom of the city".

It is entirely symbolic/honorific. Since serfdom is long gone, there are no privileges or protections to be gained by not being a serf, so getting a "key to the city" is just an indicator that the city government appreciates something you've done.