They need to have a choice, but it doesn’t necessarily need to be given just before they’re killed.
In a 2005 interview with the Leaky Cauldron, JK Rowling confirmed that it really was the choice that made Lily’s sacrifice protect Harry, and why James’s death didn’t protect her:
JKR: The caliber of Lily's bravery was, I think in this instance, higher because she could have saved herself. […] She did very consciously lay down her life. She had a clear choice—
ES: And James didn't.
JKR: Did he clearly die to try and protect Harry specifically given a clear choice? No. It's a subtle distinction and there's slightly more to it than that but that's most of the answer.
So the sacrificial protection actually comes from two aspects, both of which are present for Harry in Deathly Hallows:
Being given the choice to save yourself, and consciously dying anyway.
For Harry, this comes with Voldemort’s ultimatum, and his decision to go into the Forest willingly.
Nobody is coercing Harry to go the Forest; he goes of his own free will. His choice comes when Voldemort asks him to surrender, and gives him a one-hour deadline. When he walks into the Forest, he could just has easily have walked away from the fight, and never returned. That’s where he had a chance to save himself.
Instead, he walks into the Forest, knowing that he’s going to die, with no defence or backup plan. As far as he’s concerned, this is the end of the line. So that’s the first part.
If he’d been carried into the Forest by Slytherins, kicking and screaming, then this wouldn’t have worked. He had to choose to surrender to Voldemort.
Dying with the specific intent to protect somebody else.
This comes from the exact wording of Voldemort’s ultimatum:
“I speak now, Harry Potter, directly to you. You have permitted your friends to die for you rather than face me yourself. I shall wait for one hour in the Forbidden Forest. If, at the end of that hour, you have not come to me, have not given yourself up, then battle recommences. This time, I shall enter the fray myself, Harry Potter, and I shall find you, and I shall punish every last man, woman, and child who has tried to conceal you from me. One hour.”
By surrendering to Voldemort, Harry hopes to protect his friends from this punishment. (Note that Voldemort doesn’t specifically say death, which is perhaps why the protection extends to non-lethal curses and spells).