I was milling a 20cm long element from MDF today and found that my 3040 Y axis is off by ~0.5mm to the left after traveling the 200mm distance. You can see that the second picture shows the bottom-left corner edge being a little off (element is rotated 180 degrees along Y axis, so the error is half of the deviation shown on picture).
What is the best way to compensate this deviation, by mechanical correction or in the software or other?
As I see my first CNC I have built from plywood was not much worse than that.
You should find the reason. The software calculates the number of steps to spew out when moving the CNC but if the reference figure is wrong it will output an incorrect number of steps. If your reference number of steps per movement unit is correct, it is important to find out exactly why it moves incorrect. It could be anything from wear to incorrect dimensioned parts to noise.
Look up the diamond, circle, square test. It is an industry standard. Your bed will be mechanically off fractionally. Or if you are use two steppers, or one with two screws/gt2 for one axes they could by slightly misaligned.
I could think of a many reason, from what you have described and the pictures. I’d say it looks like your missing steps in the Y. When you take light passes . 060 or less, does the issue go way? Do a simple 5.5" x 5.5" square at a light and reasonably slow feed rate. If problem doesn’t show up. Push the depth and feed until it does. Also any chance your Acceleration and Velocity on the edge? I’d try slowing down the Acceleration.
This is where I would start from based off what I’m reading into your post.

