With the LSP and inheritance basically means: the child class can do everything that the parent class can and a bit more.
And here comes the problem:
-For a square : you can fold a square into a half-square triangle. Which mean you could make a method: "makesquaretriangle". This is not true for all rectangles.
-For a rectangle : If you multiply the height by a factor, and the width by the inverse of that factor, it will still have the same surface area. Which means you could make a method: "doublemyheightbutkeepsurface" which doubles the height and automatically halves the width. This is not true for a square.
For a square : you can fold a square into a half-square triangle. Which mean you could make a method: "makesquaretriangle". This is not true for all rectangles.
For a rectangle : If you multiply the height by a factor, and the width by the inverse of that factor, it will still have the same surface area. Which means you could make a method: "doublemyheightbutkeepsurface" which doubles the height and automatically halves the width.
This is not true for a square.
So you see, both square and rectangle have methods that don't make sense on the other, that's why they can't always be substituted. And why they can't inherit from each other either way.
The LSP is specifically for the cases where you want to either inherit A from B or want to inherit B from A, but can't. Other cases where you inherit both B and A from a common base class are out of the scope of the LSP. So your solution has nothing to do with the LSP.