As someone said, don't use WD40 it's for water displacement, it's not an oil/grease. Get a good grease such as lithium grease or even white grease. Put some grease on the catch mechanism (including the latch at the top of the hood) and work it back and forth with a screwdriver to loosen it up. Also helps to 'exercise' the pull handle from the interior of the car.
I didn't check on the Z4 but if it's like e36, e46, and e39's then there are two rubber adjusters used to line up 'how far' the hood closes. Sometimes these adjusters work their way up and need to be screwed by hand closed a bit more so the hood can go down low enough to trip the catch. I'll check mine when I get home.