Most of these laws were written in Europe when staff leasing from external agencies was legalized at the end of '90/early '00.
They were meant to avoid what you describe.
I don't know if they work well, but it's better than nothing.
One exception is concultancy agencies, but they are usually much more expensive (and offer better salaries), so that's mostly to avoid dealing with the recruiting aspect and risking bad hires.
Temporary positions is a problem for nurses, in kindergartens and, perhaps ironically, for professors.