Workaround
You may be able to prevent this bug from occurring in either of two ways:
If you plan to kill or remove any villager from a village, break its workstation first.
Break and replace the workstation of any new villager before trading with it for the first time.
Updated description by @unknown
Steps to reproduce:
Get a villager who has never traded to link to a workstation without changing its profession to match. (
This is the hard part, and I am not sure how to reproduce it. It happened for me twice while testing MCPE-63311.See comment below. Fortunately, I have a test world save in which this step is already done
--the fisherman is linked to the smithing table.)
Trade with the villager.
Break the workstation.
Place a workstation of the same type as the one you broke.
Expected result:
The villager keeps the profession it had when you traded with it.
Actual result:
The villager changes profession to match the workstation.
Original description
I had a villager turn into a librarian who sold mending 1 for 10 emeralds. I traded paper twice and four times for mending books. After walking away and coming back he had changed into a fisherman. I know for certain that the mending villager changed because he was locked in a room with another mending villager. Both had beds and workstations. I removed every single barrel from my base (Which counted to about 120 after I was finished) and he refused to change profession despite no barrels existing. The odd part being that he retained his previous librarian level locking him into the fisher class.
Edit to Bug.
Ive been working on figuring out details. The villager hall I have now currently can have 120 villagers. It seems most if not all villagers will swap to a new profession even if max level (when removing the workspace linked to them). I think this bug may be related to villager tracking which I believe will be fixed in the nether update. This may just be a side effect of another bug.
Related issues
is duplicated by
relates to
Attachments
Comments

Did this happen in a Realm or a local world?

On a Realm
We're having some difficulty reproducing the issue - could this have been a Villager that hadn't been traded with at all since the Village & Pillage update?

I just had the same issue with Librarians that I have traded with. Traded numerous times with a librarian for mending books to lock trades in. I added a few other librarians (all had been traded with to lock in trades) to my trade hall. When I went to trade with them again, their trades had all changed. This was also on a Realms world.
If you have a copy of the world available, you might like to upload a copy of it for investigation.
On Windows 10 you can use the Export world feature.
On Android or iOS you need to use a file explorer to navigate to Device storage > games > com.mojang > minecraftWorlds
On Xbox or Switch the only way is to upload it to a Realm, and then download the world on Windows 10 or Android/iOS. (Please do not purchase a Realms subscription just to provide a world to us - but if you have a Realm already this may be a viable option if you wish to do so.)
If the world is larger than 10MB you can upload the world to OneDrive or a similar file sharing site, and then share the link.

I reported the same phenomenon under MCPE-60782 (Windows 10). I have only experienced this once. But it really did happen: A villager changed his profession even though he had already been traded.

This has happened to me. I was making a starter trading hall, with one of each job block available. I traded with each villager once to lock them to their profession. I logged back in one day to find my Librarian was now a butcher, with the same XP level they had previously, but for the wrong job.
Unfortunately the save file corrupted and I deleted it, so I cannot help with that.
PS4, single player, survival, offline.

This happened to me on a realms server, I had a level 3 librarian with an Unbreaking enchanted book trade which I put a name tag on to keep track of it. It seemed to have claimed a composter which had been unclaimed (I had 3 composters and only 2 farmers) and turned into a farmer despite not being a novice anymore. All of its trades are now farmer trades from levels 1-3. It still retained the name tag as well. I'm not sure how old the world is but the village was created from cured zombie villagers in an underground base after the village and pillage update. Unfortunately I don't have access to the world file since I'm not the owner of the server.

This seems to mostly happen in multiplayer, interesting.

Just hapenned to me on ios, single player world, librarian kept the profession and level but changed trades. version 1.14.60

Just happened to me in a local world that allows multiplayer. After an illager patrol that spawned inside the smithy killed off all armourers I respawned the armorers in creative, made sure they traded different pieces of armour and traded with them until they reached master level. That happened Friday.
Saturday morning I loaded the game and looked into the smithy and there were tthree armorers and one librarian although all the reading stands in the village should have been occupied by libarians.

Confirmed using test world
[media]
The fisherman wants to be a toolsmith and will gladly change professions after buying all the fish you want to sell him, if you just get rid of that unsuitable smithing table and install a proper one.
The NBT data for the fisherman is interesting. The picture below shows the test world open in 2 instances of MCCToolchest, one with the village POI list showing the smithing table linked, and one with the chunk entity listing for the villager showing that he has fisherman trades but wants to be a toolsmith.
[media]

Had a village who was at master trade level switch from be a librarian to a shepherd, after buying about 20 Mending books from him(my only mending villager. This happen on in realms v 1.14.60, and I had other villager change profession as well.

Step 1 from the description above can be reproduce as follows:
1.a. Get a villager (A) to link to a bed and workstation.
1.b. Spawn a new villager (B) nearby, but do not give it a workstation. (This also works with villagers that grow up naturally from children. I haven't test cured zombie villagers yet.)
1.c. Relog.
1.d. Kill villager A (or move him outside of simulation distance and wait 25 minutes for the village to remove him from the dweller's list).
Villager B then links to the bed and workstation, but does not change profession to match.
Here is a full demo video:
[media]

Villages are a pretty huge part of Minecraft, give your otherwise quiet worlds a bit of extra life, and as a bonus you get to feel a little less alone. Part of being such a big deal is just how many mechanics villages and their inhabitants have.

In 1.16 the incomplete linking described in my previous comment can prevent iron golems from spawning. See MCPE-65202.

I play single player world with cross platform multiplayer open on PS4 v1.16.0
I previously logged my issue (MCPE-88105) which has been resolved and linked here. I had approximately 20 villagers established prior to the 1.16.0 update. I had every trade and had locked them all in to their trades. The villagers were continuing to breed. An Iron Golem had not generated. A few days ago I was forced to delete and reinstall the game after it failed to load (this is happening weekly), freezing on the Mojang screen. On entering the game, I was left with only my Farmer, Toolsmith, Fletcher, 3 unemployed, 2 Nitwits and 2 Librarians. However, one of my Librarians was locked in as Mending and had been traded with many times, but was now locked with Multishot. Yesterday, the game crashed approximately 3 times in one afternoon and at some point, I lost the Toolsmith and Fletcher as well. Furthermore, the 3 unemployed villagers will not accept any trade block and remain unemployable. They are not Nitwits. So much time, effort and resources have been put into creating this world and the losses have been devastating. Even with a fix, I won’t reclaim what has been lost.

We play on Xbox one, on a Microsoft Realm. We have experienced this problem for the last year, but intermittently and sporadically. The usual scenario for us is that my wife has traded with a villager and achieved max level for that villager....most often the Librarians and the Farmers that then get nametags so we can tell Mr. Carrot from Mr. Potato. and Mr. Mender, from Ms Unbreaking. with no breaking of stations, or trying to transport the villagers anywhere (our towns are walled with Golems and villagers are allowed to free roam within the walls) we will show up one day.....and they've just decided to change professions. Ms. Efficiency 5 is now a Fisherman!

I had several armorers and smiths with really good armor/weapons switch to farmers when I put down composters. Meanwhile jobless villagers never choose a profession, and just wander around aimless, even if I put a new job block in front of them. If I break an existing job block, the villager immediately switches profession while the jobless remains jobless.
All of my existing villagers with established jobs of which I regularly trade with just randomly switch if I put down new blocks instead of jobless villagers claiming them.
I've spent countless hours grinding for trade resources to upgrade their levels and get decent trades, and then they just switch jobs spontaneously. Extremely frustrating.

Was just able to record an instance of this on PS4 (Minecraft_20200913000506small.mp4). We had a librarian with a book we wanted, traded with him to lock it in. Needed to move lectern to a zombie-proof house and he unlinked despite the trade. No other workstations available so he remained unemployed until we placed his lectern again, at which point he relinked with a different, far worse trade which he was then locked in to.

Also experiencing this issue on PS4. I levelled up my villagers to level 5 before moving them into my trading hall (one at a time, making sure each villager was linked to the workstation directly in front of them before leaving). My trading hall is chunk aligned with each villager 2/3 blocks in from the chunk boarders and at least 200 blocks away from any other villager tech (beds, workstations, villages etc). I logged off for a while and when logging back on I had:
2 level 5 masons that were now a level 5 librarian and a level 0 Mason.
Level 5 Fisherman with string and cod trade now had completely different trades (coal and salmon I think).
Level 5 librarian now level 0 cleric
I also found that when cycling through trades the villagers would almost become stuck and wouldn't refresh or would stay as e.g. farmer even though the composter had been removed and re-logging doesn't fix the issue.
This is in a completely new world (started this month) and it's becoming increasing frustrating to spend so much time gathering resources and levelling up villagers only for them to become something completely different for no reason.

Working on getting Expert Stone Masons to offer every color of terracotta, but my stone masons either switch their offering to a different color, or change professions entirely.
I tag each villager with their terracotta color when I "lock them in" after trading with them. In fact, there's no way to know which color terracotta a villager will offer UNTIL you trade with them, that should lock them into that profession at least.
However, I keep coming back to something like this:
[media]As you can see, my formerly Light Gray stone mason has changed to an armorsmith.

I have been having this happen in my 1.16.40 game. BDS hosted on my machine.
Sometimes villagers go missing, sometimes they change professions.
This last time it happened to three villagers at the same time - all were enchanters, in the same room with three lecterns and all traded up at least two levels.
All kept their levels. One stayed an enchanter, but his books changed.
And the profession only changed once - after that, it "stuck". I've destroyed the lecterns and replaced them, but the villagers are not changing back.
All were recently healed from being zombies.

This bug still occurs in 1.16.200. I have a trading hall with all the villagers stuck in individual spaces and a max level farmer somehow changed into a max level cleric. I did not remove his work station. The only thing I did was move some brewing stands to switch villagers on another part of the trading hall.

@Derick Wolfe: Was the farmer created prior to 1.16.100? If so, he would have been affected by this bug before the update, since the error with the villagers' professions actually occurred when they first linked to a workstation. If you can reproduce switching professions after trading with villagers created in the current version, please create a new ticket.

Yah I'm not sure why this says its resolved because this has been continuously happening even in 1.16.210 and above

The specific reproduction steps described on this ticket no longer reproduce the bug after the fix in 1.16.100.
For villagers changing professions after trading, after the 1.16.100 update, see MCPE-117852. Please comment there if you have steps to reproduce the problem.