It’s basically impossible for an American company to defy the American government. They can try in court but ultimately the government has F-22s and nuclear weapons and Apple does not.
If you want to watch a fictional version, the scifi shows Continuum and Dark Matter both portrayed a future where corporations ran the governments or were the governments.
All laws are backed by the threat of overwhelming violence. If you have a corporate fine, and you don’t pay it, the state will seize your property. If you stand in your doorway and obstruct the sheriff, he will arrest you. If you resist the arrest with weapons, he will bring his own weapons. If you have enough weapons to require a military response, a military response is what you will get.
If the military went against the law then they'd be rebels. The fed doesn't let rebels drive the tanks.
They don't need to use weapons to spy on citizens. The constitutional right to privacy was stripped in the Bush era and it's been open season ever since.