Amazon lost money every quarter as well for years. There is a huge market in government and defense IT globally that Palantir could potentially tap into. Historically, it's been IBM's gig, but that could change very quickly.
Government and defence IT is a service business - where do you invest the money?
Note: I'm not saying they don't invest the money, just curious where it goes.
The other part of .Gov contracting is integrating so tightly that you become a defacto standard that is not easily replaced. Then lobbying to ensure you keep that position.