My e36 did the same thing with me a few months ago.
I must state that my car has an aftermarket Sanji alarm system:
I had the car in for a service and somewhere the mechanic's shirt or something must've hooked on the bonnet alarm trigger switch. This was bent, didn't make proper contact when the bonnet was closed, and resulted in the alarm being triggered as soon as you lock it.
Bent the breaker switch back into position, and problem solved.