- When Tim arrived home, the children did their homework.
- When Tim arrived home, the children were doing their homework
Both forms are correct but they have different meanings.
In sentence #1 the children did their homework after Tim arrived home.
In sentence #2 The children had started doing their homework before Tim arrived, and it was ongoing when he arrived.
- When the bank guard spied the sinister-looking customer, he drew his gun
This means that the bank guard pulled out the firearm after he saw the suspicious looking customer.
In the second example I would add the preposition "on"
- When the bank guard was spying on the sinister-looking customer, he drew his gun"
This means that the bankguard had spent some time looking at the customer in secret before pulling out the gun. I would prefer to use "while" instead of "when" because it suggests that two actions happened at the same time.
To spy means to spot, see, identify a thing or person, usually it's in the distance or partially hidden.
To spy on something or someone, means to look at that thing or person in secret without being seen.
‘He was spying on Selina, watching her every move.’
‘She's there to spy on her cheating husband.’