The keyhole locks require a key item hidden in the level. Those are not exits, they contain treasure! The other locks are opened by using a coin. You can get a coin by pressing B while holding Up. You need at least 10 coins in your countr to do it, though.