In Terminator Dreams, why did Daniel have to die at the end of the book?
There are a couple of reasons why it happened. Some are structural (defining how the story works) and some are personal (defining how Daniel works). Several of them relate to Daniel's amnesia.
Starting with the personal reasoning... Daniel is a man who lost the first half of his life when he experienced amnesia in the hours before the events of J-Day. It's reasonable to conclude that he has, ever since, lived in fear of the thought that it could happen to him again. This would give him a certain instant-gratification complex, though "gratification" isn't exactly the right word — but he'd be adverse to making long-term plans whenever a short-term plan could be substituted.
Basically, he realized that he could make another contribution to the lives of the people he loved — implant some programming into Skynet that might, some day, give the human Resistance the edge in the conflict — and decided that this outcome more than warranted the risk to his life. Coupled with his instant gratification characteristic, it meant he'd dive in again immediately, whatever the risk. Orders wouldn't have been relevant. He wasn't of a military bent in any case and would have disobeyed.
Structurally speaking, his amnesia was caused in the first place by the fact that Danny was connected with Daniel when Daniel died. If Daniel had not died, Danny would not have had that trauma and would have retained his memory throughout the events of J-Day, resulting in a future that would have been very different for him, Mike, etc., and therefore the subsequent events of Terminator Dreams would be irrelevant.
Thematically, a lot of the book was about the older generation making sacrifices for the younger, and without any actual sacrifice the book would have lacked any punch.