When has two meanings:
1 I visited him when (specific) I was in Manchester = at the time that; on the occasion that
2 I visit him when (general) I am in Manchester = whenever, at any time that; on any occasion that
(Meaning 2 also tends towards “if”: I sometimes travel to the North. When I am near Manchester I might visit him. ≈ if)
Your examples are all inverted. They are fronted by a type of adverbial – they are all capable of being re-adjusted, which is the test to see if they work.
- You should be cautious when walking in a dark alley,.
- Be cautious when walking in a dark alley.
- Be cautious walking in a dark alley.
- You should be cautious walking in a dark alley.
For the purpose of your examples, there is no significant difference between “should be cautious” and “be cautious”
Thus the only examples we need are
- When walking in a dark alley, be cautious.
- Walking in a dark alley, be cautious.
And both are acceptable although the context will play a part in deciding which is most appropriate.