The reason for this bug is obviously a mathematical algorithm, which handles the 180° transition incorrectly. (Btw: a similar bug can sometimes be observed at the 360° transition.) In the example above, it is only a strange effect, which could be ignored with a grin. But imagine an autopilot controlling an aircraft or ship. Assume it has to perform a slight course change to portside, say from 5° to 355°. Due to a software bug, the vessel performs an (almost) full circle of 350° to starboard instead. This could lead to severe problems, even a crash, if there is an obstacle.
The mathematical solution for correct behaviour is the following: Always use angular differences, normalised to a range of +/- 180°. These deltas can be used for further calculations, e.g. filtering. Then the final result has to be adjusted again, this time to the range of 0°...360°. Sounds complicated, but in fact it’s quite simple. And it provides correct results.