The “length of an object” is not a well-defined concept, because extended objects are problematic in relativity. Indeed, an object is viewed as a set of simultaneous events. But simultaneity depends on the reference frame, so that the identity of the parts of an object depend on the frame. So it is best to stick to events.
Two events separated by $L$ in their rest frame, and simultaneous in that frame
$$x_1=0,\quad x_2=L,\quad t_1=0,\quad t_2=0$$
leads to
$$x_1'=0,\quad x_2'=\gamma L,\quad t_1'=0,\quad t_2'= -\gamma v L/c^2$$
On the other hand, 2 events separated by $L$ in their own rest frame, but occurring simultaneously in the moving rest frame
$$x_1=0,\quad x_2=L,\quad t_1'=0,\quad t_2'=0$$
leads to
$$x_1'=0,\quad x_2=L/\gamma$$
which is the Lorentz contraction.
The former corresponds, say, to two flashes emitted at the front and back end of a rocket, simultaneously as viewed by the rocket's captain. These are observed from a system at rest as being further apart than on the rocket.
The latter corresponds, say, to two photographs of the rocket, taken from the ground, at 2 different positions.
The two results you compute are both meaningful and correct in appropriate circumstances. But they are never both applicable, so no contradiction arises.