I'm not sure what went wrong exactly, but a common issue people run into with lofts is caused by the fact that FreeCAD tries to match vertices to vertices. If you use the split edge tool on your square to create 8 edges out of the existing 4 (maintaining the same square shape), it should loft smoothly to the octagon.
If the loft appears twisted it only means you need to change the order in which you created the geometry. FC in addition to matching vertex to vertex will also match them in the order they were created. This allows you to purposely create twisted shapes, but sometimes can happen inadvertently also.