Here is how I understand it. I repair simple issues with lenses, and have dissected a few ones that were totalled.
Inside the lens is a small resistive element with a wiper. The resistance changes as the focus element moves. This is converted to digital by the chip in the lens and the lens position sent to the camera. The lens chip has a table of resistance versus focus distances, it is used to determine the focus distance versus resistance reading. The lens chip can be reprogrammed by Canon or a authorized third party repair station. (Canon sells them the programmer and software to do this)
When the camera does a phase detect, it sends a command to the lens to move focus to a certain position. There can be inaccuracies in the system that add up to being slightly off focus. AFMA tells the camera to offset the command it sends to the lens so that the lens focuses slightly closer or slightly further away.
The problem lies with the linear accuracy of the element and programming in the lens. The lens will now focus correctly at the distance you adjusted it for, and might be off at other distances. If thats the case, and its too severe, Canon can adjust the lens to be accurate at multiple distances, but the user can't.
Canon cameras contain information about all the EF lenses and the commands to send to them. Third party lenses tell the camera that they are a Canon lens and then translate the command they receive to their lens. This can cause even another step that adds to inaccuracy, but it can be adjusted by AFMA as well.
Its a lot more complex that a person might think.