I think there are certain establishments that are so "established" that we almost always use the definite article.
"I'm going to the shop" refers to any of the many grocery shops in the surrounding vicinity, even if one is not in the habit of going to any particular shop. We say this because all that matters us is the fact that we're going to go somewhere that provides groceries. We don't view a grocery shop so much as an individual place, but rather as an idea, if you get my meaning

. You could also say "I'm going to a shop", but "the" sounds slightly more idiomatic.
"I'm going to the bank" means any one of the banks which one normally frequents. This is far, far more common than "I'm going to a bank", because banks are all pretty much the same. Most crucially, all banks
provide the same service. This also applies to "post office" and other such places.
"I'm going to the supermarket" refers to one of the supermarkets nearby, but most probably to the supermarket which one most regularly goes to. "I'm going to a supermarket" means that one does not know which one will go to, and I think it would be common enough to say "
a supermarket" in this context because there can be quite a significant variation between different supermarkets. They can even provide different services - some offer only food, while others might also sell other items.
"I'm going to the bookstore" most probably refers to one particular bookstore, since there don't seem to be as many bookstores as there are grocery shops/supermarkets/banks. In any case, there would be good reason to go to one particular bookstore, since each bookstore can differ a lot from others, in terms of size, clientelle, etc... So if you were going to go to a bookstore but didn't know exactly which one, you'd definitely say "I'm going to a bookstore."
The same applies to restaurants, because restaurants are all so different from each other and it really
matters which one you go to. So, I would never say "I'm going to the restaurant" unless it was very clear in the minds of both the speaker and myself which restaurant I was referring to. I would either say "I'm going to a restaurant" or "I'm going to (name of restaurant)."
I would almost always say "I'm going to
a department store" beacuse department stores are very unspecific places where one tends to just go in and have a look around. It's not like when you go to a supermarket for the weekly shopping with a list of "need-to-be-bought" items in your hand. Crucially, not all department stores provide the same service. Also, if I want to go to a department store, I usually have to travel a long distance (into city centre) and there I will find several different department stores.
You would always say "I'm going to
the library" and hardly ever "a library" because one tends to go to one particular library all the time. And also, they all provide the same service. This also applies with "the gym", "the sports centre", "the golf club" or anything that one is a member of.
If you use two different libraries that are nearby, you would still say "I'm going to the library", and you would go on to specify which one, if the person was interested enough to want to know

This same thing also applies to "City Hall", "Ward Office"and "District Court" because there is usually only one of these nearby.
In the case of "ATM", I would actually say "an ATM", even though all ATMs clearly provide the same service. I suppose this is because there are so many different ATMs scattered around in different locations and I mightn't have a clear idea at all of which ATM I'd go to - I'd simply use the first one in sight. However, if I did know which specific ATM i wanted to go to, and
crucially, if the person I was speaking to also knew which ATM I was referring to, I would say "I'm going to the ATM".
Hope this wasn't too confusing

My brain is about to fall out...