why magnetic field has its direction perpendicular to that of electric field?
It doesn’t. In general, at any point, the electric field can have any direction and the magnetic field can have any direction. They are perpendicular in, say, a plane electromagnetic wave, but there is no relationship between their directions in a general electromagnetic field.
we have defined magnetic force as an electrostatic force in a different frame of reference
That is not how magnetic field is defined. Magnetic field is defined by the Lorentz force law. This definition requires only one reference frame.
It is a conceptual mistake to think that every magnetic field is simply a Lorentz-transformed electric field. For example, you cannot Lorentz-transform away the magnetic field of a circular current, because there is no inertial reference frame in which all the moving charges are at rest.