I've heard that in several countries, including Malay and Iran, being an atheist can get you a death sentence.
It's worth mentioning that (as far as I know) these laws are rarely applied, if at all.
All of these countries are Islamic countries.
This might be true nowadays, but from a historical perspective this was also true for christian countries in Europe, at least until the Middle Age.
More generally, laws to enforce a state religion have been in use in many countries. Some of them had laws to punish blasphemy until very recently, e.g. Ireland.
Now, Islam itself is already pretty close to atheism, rejecting all gods but one (Allah). So it's legal to believe in Visnu, or Thor, or Zeus, but illegal to share similar beliefs with Muslims that none of those gods exist.
This interpretation is completely wrong, Islam is not close to atheism at all.
Why, then, do these laws exist? Do these countries hate atheists, and if so, why?
"a country hating X" doesn't make any sense. It's a complex combination of historical, cultural and political factors, but to simplify:
- modern democracies were not born this way. In Europe, laws separating church and state came from centuries of struggle and religious discrimination. Some countries still don't separate church and state completely, which can be seen as a remnant from the power that religion used to have.
- the muslim countries are at a different stage of "democratic development" compared to western democracies. Some of them haven't been independent for a long time, and most of them don't have their national identity built around a history of struggles for democratic rights.
- The education level plays a big role in both religious feeling (negatively) and desire for democratic rights (positively). Countries in which the population hasn't reached a high level of education yet (or only recently) simply didn't have enough time to evolve culturally.
[added] In a much broader perspective, there are lots of benefits for a society to accept religious freedom and to accept diversity (not only religious) in general. But it's a slow process which takes place over generations. One may also note that acting (or pretending to act) in the name of religion is often a cheap way to gain or maintain political power.