Yes, it was necessary (at least in the opinion of the brass-hats).
Ender is simply too empathetic for his own good. If he knew that he was sending real men and women to their deaths, he'd have frozen under the pressure or simply refused
"I can't win battles if I'm so terrified of losing a ship that I never
take any risks." Mazer smiled. "Excellent, Ender. You're beginning to
learn. But in a real battle, you would have superior officers and,
worst of all, civilians shouting those things at you. Now, if the
enemy had been at all bright, they would have caught you here, and
taken Tom's squadron."
And if he'd known that he was fighting a real enemy, he wouldn't have made the decision to use the Little Dr on the Bugger's homeworld.
"You made the hard choice, boy. All or nothing. End them or end us.
But heaven knows there was no other way you could have done it.
Congratulations. You beat them, and it's all over." All over. Beat
them. Ender didn't understand. "I beat you." Mazer laughed, a loud
laugh that filled the room. "Ender, you never played me. You never
played a game since I became your enemy."
Graff explictly spells out the need for the ruse;
"It had to be a trick or you couldn't have done it. It's the bind we were in. We had to have a commander with so much empathy that he would think like the buggers, understand them and anticipate them. So much compassion that he could win the love of his underlings and work with them like a perfect machine, as perfect as the buggers. But somebody with that much compassion could never be the killer we needed. Could never go into battle willing to win at all costs. If you knew, you couldn't do it. If you were the kind of person who would do it even if you knew, you could never have understood the buggers well enough." "And it had to be a child, Ender," said Mazer. "You were faster than me. Better than me. I was too old and cautious. Any decent person who knows what warfare is can never go into battle with a whole heart. But you didn't know. We made sure you didn't know. You were reckless and brilliant and young. It's what you were born for." "We had pilots with our ships, didn't we." "Yes." "I was ordering pilots to go in and die and I didn't even know it." "They knew it, Ender, and they went anyway. They knew what it was for." "You never asked me! You never told me the truth about anything!" "You had to be a weapon, Ender. Like a gun, like the Little Doctor, functioning perfectly but not knowing what you were aimed at. We aimed you. We're responsible. If there was something wrong, we did it."