It appears to work because the component pieces are close enough to the dimensions needed to disguise that the hypotenuse in the second (bottom) example is not quite a straight line. Using the Pythagorean theorem you can determine that the missing square is just the result of a fool-the-eye trick.
Just look at the little slivers of space where the hypotenuse slices through a square. They don’t match up on the top and bottom diagrams.
Look at the dimensions of the dark green triangle: 2 high x 5 wide.
The red triangle is 3 high. If the slopes match, then it would be 7-1/2 wide, but it isn’t. It’s 8 wide.
In the top picture, the hypotenuse is concave (bowed inward).
In the bottom picture, the hypotenuse is convex (bowed outward).
That’s where the extra square comes from.
To back it up mathematically, the slopes of the two component triangles aren’t equal, therefore, the hypotenuse of the whole triangle itself is not a straight line.
Red triangle slope is 3/8 = .375
Dark green triangle slope is 2/5 = .400
The slope of the whole triangle is 5/13 = .384615…
Also, the area of the large triangle is 32.5, although the sum of the components only add up to 32. A little eye trickery…shorting the top triangle of 1/2 and adding 1/2 of empty space to the missing half to get one whole empty square.