We assign beds, but actually go to the dorm with them (we are small enough to do this, 34 beds, so maybe you can too?). "This is your bed, here's your locker, towel, etc." This generally cut down on any one switching beds on us. It will still happen once in awhile, especially top to bottom if the bottom bed opens up and is cleaned. (Of course they aren't realizing we already assigned someone else to that bed). Often we'll catch this in the later afternoon when checking all of the cleaning and can resolve it then. Sometimes it happens when taking a guest to the dorm. In this case, it's a bit embarrassing, but we are at lease able to figure out pretty quickly what happened and assign the new guest a different bed (i.e. the top bed where the person moved from). In this case we often have to make it quickly, as the bed was not on the cleaning list, since we did not know the current guest had moved.
I can see how if you didn't know that a guest had switched beds on you, or taken a different one than you assigned, and you are not there to see that it would mess up the system. If the new guests comes and tells you, you can then of course assign them to a different bed and switch things in your PMS. But if they just take it upon themselves to take a different bed, then the cycle continues. Therefore one suggestion I would have (if logistically possible) is to walk with the guest to the dorm so you can tell quickly if that letter you assigned is dirty/taken. If not, consider asking the guest to let reception know right away if their bed is not available so you can fix things.
We mostly use communication between the cleaners and reception to solve/prevent this. Our lockers are under each bed, so we train the cleaners to check these with the rule that 'Nothing should be left behind'. If there is a whole bag in there, or clothes on the bed, then they are to come back to reception so that we can check it out. It's usually then that we realize someone switched beds (just using some logic and guesswork). We can update the person who switched in our PMS so that the actual free bed will now show up as free, and we clean that one instead.
Another idea I've seen at hostels and implemented recently in ours is good size bed cards (5 x 7/ half A4) with the guest's name. We do these as a way to have important info at their fingertips (wifi password!) but also so that other travelers will know their name. We have the cleaners bring them to reception of the beds they just cleaned. We assign beds in the morning and have the reception write the incoming guests' names on these cards (they are laminated & we use wipe off markers). Then when reception checks beds to make sure they were all cleaned properly, they pop the sign on each one (magnetic on steel bed frames). This could be done for either assigned or unassigned beds. You could do it like I just suggested, or choose to not assign beds and use it as a way of knowing who has checked out that day and which bed(s) need to be cleaned in that room. They can choose whichever bed they want in that dorm but their name needs to be on it.
An idea for the key issue: our keys are assigned to each guest, but not in relation to their bed. For example, our keys are numbered but our beds are actually named after things around the city. If we give a guest key #10, it says it in the system by their name. This is functionality built into our PMS, but you could also do as simple as a google spreadsheet. Then if a guest does an early checkout, we find key #10, find the guest who had that key, and know who to refund their key deposit. You would still have the issue of which bed was theirs, but hopefully one of the suggestions above would have solved that. However if you have the key assigned to the bed, it may always mix things up.
For example, Joe decided to check out out early and drops his key. You think Joe is in bed A, but really he's been sleeping in bed B, and you think Sam is in bed B but he's really in A. Now you get the key in the drop box for bed A, and accidentally make Sam's bed, instead of Joe. Sam comes home to a clean bed (how nice!) and Joe's bed stays dirty. Now you assign someone to the free bed (A) but come check in, the new guest will find Sam in that bed and Bed B to be dirty. Not fun.
It's hard to say if any of this will work for you, as I don't know your exact logistics at checkin, etc. But maybe that will at least give you some things to consider. Good luck!