Apple are being ordered to build a custom firmware that doesn't extend the length of time you have to wait between attempts to guess the pin code, and to allow pin codes to be sent remotely via a physical cable. They do not have the keys to the device, and so are being ordered to make it feasible to brute force it.
People have been saying that the phone will be sent to Apple because the govt has said that Apple will retain their ownership of the code, but that's just referring to the source used to build the firmware. Apple are saying no because the firmware they supply is unlikely to stay in the govt's hands for very long - it will be leaked, and then made available to any and all black hats that want to examine it for clues to breaking security in other phones.
I'm kinda with Apple on this one, but I question their motives.