I've had a similar problem with a cat, previously perfectly housetrained, who all of a sudden decided that the best place to pee was my bookshelf! She then started spraying pee all over the flat, ignored her litter tray, and started being sick a lot. She didn't have a catflap at the time (we'd only been in the flat a month or so) and I was leaving windows open for her instead. Here is what I learnt from reading several books, asking around etc:
Your cat is peeing in your bed because it feels safe there (it smells of you, is comfy and soft).
This is because another cat has invaded its space. Even though you have locked the catflap the cat still thinks that the outsider might get in. It holds its pee for as long as possible (too scared to go outside / use its normal toilet spot) and then finally lets go in the one place it still feels secure.
To solve the problem you need to board up the catflap on both sides and keep your cat indoors for a couple of days.
As you have more than one cat it is also possible that the invader has unbalanced their relationship slightly. One cat may be 'guarding' the litter tray so the other one can't use it, hence the puddle. Introduce more litter trays to your house. Choose places which are sheltered (ie in corners, behind furniture etc) but not too restricted (so the cats can still move around freely). Dry-clean the duvet, clean the mattress thoroughly etc as the scent of urine must be eradicated. It would probably be best to keep your cats out of your bedroom for the time being.
Keep the litter trays very clean and consider restricting your cats to those rooms which have trays in them only.
Once the cats are happily using their new trays, you can start letting them in and out again, but open the door yourself. Start off with a regular time so the cats incorporate this into their routine. Do this for at least a month. Hopefully by this time the invading cat will have stopped trying to break in. You can then re-introduce the catflap, but keep it locked & covered at night for the first few weeks.
You might want to try one of the magnetic / infrared catflaps to ensure only your cats can come in. You should also take the time to train your cats to use the flap properly as other cats will be much more likely to investigate an open gap than one with a physical barrier. Do this by taping the door open, then not-so-open, then almost-closed etc until your cats have got used to the idea of pushing against it rather than just stepping through. Be warned - if the cat thinks it can get you to open the door for it, it WILL! Sometimes the only answer is to put the cat outside and the food inside, then WALK AWAY!
Once your cats realise they have free access to the outdoors during the day they will gradually stop using all of the litter trays, probably settling on a favourite one each . You can remove some of them (but only when they have been out of use for a couple of weeks!)
Depending on the invading cat, you might want to keep the catflap locked at night indefinitely and keep a litter tray indoors permanently.
Good luck!