Assume $K \subseteq H \subseteq G$ are groups. We want to show that if $[G:K]$ is finite then so are $[G:H]$ and $[H:K]$ and vice versa.
We know from the proof of Lagrange's theorem that $|G| = [G:K]|K|$ and that $|H| = [H:K]|K|$ and that $|G|=[G:H]|H|$ (even for infinite groups)
So $[G:H]|H| = [G:K]|K| \iff [G:H][H:K]|K| = [G:K]|K| \iff [G:H][H:K] = [G:K]$
So if $[G:K]$ is finite so are $[G:H]$ and $[H:K]$
This proof works if the order of $K$ is finite, but it's very problematic if it's infinite, i want to know if it's possible to formalize the last step or if this proof remains fallacious for infinite groups no matter what (I know the result is correct)
You are correct that the proof does not work if $K$ is infinite. However, the result still holds in that case. Argue in terms of cosets as in the following proof sketch:
$G$ is the disjoint union of the $|G:H|$ cosets of $H$.
Each coset of $H$ is the disjoint union of $|H:K|$ cosets of $K$.
Each coset of $K$ is contained in exactly one coset of $H$.
The total number of cosets of $K$ is $|G:K|$. From the above, it should be clear that we must have $|G:K| = |G:H||H:K|$, where the LHS is finite if and only if both factors on the RHS are finite.