This is happening because of the way polygons are displayed. In order for the geometry to be displayed it needs to be triangulated as video cards draw only triangles behind the scenes(math is easier this way and pretty much all computer graphics currently are built on that). There are two ways to triangulate the side faces in your example:

What we are observing here is automatic triangulation algorithm failing to guess what kind of triangulation is desired in this case.
Errors like this will happen from time to time if you have concave n-gons. The best thing to do here is to get used to not having them in your geometry.
You can solve the issue manually connecting vertices of any concave geometry to make them convex as you can see in the GIF. If it happens that you need an automatic way to fix these issues you can also go to the Mesh menu in the header of any 3D View panel and choose Clean up -> Split Concave Faces while you have everything selected in edit mode: