Companies do free work for large potential customers all of the time, in lots of industries. The idea is that you do something small to demonstrate your capability to take on a larger paid opportunity.
Probably out of good faith. Can't be accused of not helping the US government. Also sets a bar of how much help they'll willing to offer. Maybe also wanted control over who had access to their information, rather give it to them then have it stolen
Because complying with the government is a good idea when that government keeps giving you tax breaks and favourable treatment. Most companies, even ones that oppose some state policies (particularly surveillance), cooperate with government or get funding from them still. So not burning bridges is important. I'm sure the expenses weren't too significant but letting the project go free gives them tons of goodwill from the leaders.
It sounds like it was really just a few hours of one engineer’s time, when he didn’t have any imminent deadlines. Not enough to compromise any ongoing projects.
As was widely reported at that time, the three letter agencies were among the largest customers of NeXTStep, the software that forms the basis of the professional operating system that Apple later acquired to replace the original unorthodox (and barely functioning) software that Jobs hobbled together with a motley crew of hackers while running Apple during the DOS era. Enterprises of all kinds that had the flexibility (or pressure) to think outside of the box went with NeXTStep because it allowed totally custom applications to be developed in record time (using things like Interface Builder, today part of the visual layout in Xcode). It is totally unsurprising that they would turn to their long time partner Steve Jobs for help with a mobile solution and that he would do it for free to eventually sell of more technology to those long time customers from before he sold NeXT to Apple and became its iCEO.
It's like sticking your foot in the door on the small level, except translating it to the big picture, where spending a paltry few million on a custom iPod could lead to billion dollar contracts in the long-term.
I’m sure Apple’s government relations attorney was involved in some way and helped keep the project siloed. There was likely some contract, but is buried now.
Government pays for the work but does it through a cutout company so Apple isn't tied to work. They get the money to pay the Bechtel engineers and the government gets their iPod fairly.
Engineer hours cost the company time they would otherwise invest in their current products in development.
Why do it for free? It's not like the US Gov can't afford it.