A domain name is much more than storing an entry in a database. The root name servers are not cheap to operate. Domain names can also have glue records which mean more records in the root name server.
Also the more expensive a domain name is, the less spammy domains you see. If domains were $1 all the time, there would hardly be any domains left since everyone would register anything they can think of. Adding a price point reduces the number of unused domains.
In addition to your hardware/IT costs you have:
-ICANN's fees to get started
-ICANN's annual fees
-ICANN's fee per registration
-ICANN's variable fees (based on their expenses)
Then, you have to pay the "owner" of each TLD to be able to register .com, .me, .io, etc. It costs, for example, over $7.00 to Verisign each time Namecheap registers a .com unless they've arranged some other pricing. The bottom line is the $.98 promotion is quite a loss leader.
Also the more expensive a domain name is, the less spammy domains you see. If domains were $1 all the time, there would hardly be any domains left since everyone would register anything they can think of. Adding a price point reduces the number of unused domains.