How do I get Lydia to stop attacking people so I can progress in the quest?

Skyrim can be a buggy game.

You already recognized the problem, so it is best to just go along with the game and help it a little bit out.

Simply send Lydia home and do this part without her. She will be waiting in your house or in the hall of the jarl in Whiterun.

Sending your companion home will not teleport them out of the room and home instantly. Instead they will stop following your movement and will walk towards the exit. This can take some time and they will still engage in combat situations in this state. Go to another room send them home, maybe fast travel real quick to let some time pass and come back. They should be gone then.