No, it’s not necessary to have a website. You can register a domain without buying hosting or setting up a website. However, pretty much the only way to get a free domain is to buy some kind of hosting.