iPhone 4 screen lock through unsolicited ad
It's a JavaScript alert from the page that you're currently viewing. It's not malware or anything installed on the device—just JavaScript.

Tap to dismiss the dialog then leave the advertiser's webpage. It doesn't lock the screen, just presents a modal dialog in front of the content.