The setting you have mentioned there will work when you manually turn off the screen - on my HTC Desire it is pressing the power button.
With "Lock phone after" set to "Immediately" it will lock the phone once the screen turns off (manually or after timeout)
To set the screen timeout go to Settings | Display | Screen timeout and set it to however long you want the screen to stay on for until it automatically turns off.
The two timeouts work separately:
- Screen timeout is for when the screen turns itself off (for the battery conscious)
- Lock timeout for when the lock screen will be shown (for the security conscious)
For example, I have Screen timeout set to '2min', and Lock timeout set to 'Immediate'. So if I leave my phone without touching it, 2 minutes later the screen will turn itself off. If I immediately turn the screen back on, I will be challenged with the lock screen.
If I keep Screen timeout as '2min' and change Lock timeout to '5min', then like before without using the phone, the screen will turn itself off in 2min. However if I immediately turn the screen back on, there will be no lock screen. Only after 5min of not using the phone will I be challenged with the lock screen when I turn the screen back on.