How does haloform reaction take place if the reactants NaOH and X2 react with each other?
The disproportionation of halogens $(1)$ is an equilibrium reaction; depending on the concentrations of reactants and products it can go both ways. Since hydroxide (or more generally: a base) is among the reactants, increasing pH will drive the reaction towards the product side.

$$\ce{3 Br2 + 6 OH- &lt;=&gt;&gt; 5 Br- + BrO3- + 3 H2O}\tag{1}$$

The first step of the haloform reaction is to enolise a ketone to the corresponding enole $(2)$. This is also an equilibrium lying on the reactants’ side this time.

$$\ce{RC(=O)-CH3 + OH- &lt;&lt;=&gt; RC(-O^-)=CH2 + H2O}\tag{2}$$

So you are correct, both equilibria should be away from what is required for the haloform reaction to proceed. However, both are equilibria. For both, we can measure an equilibrium constant and use it to calculate the concentrations of both the enolate and the free dihalogen. I don’t have all the numbers here, but the result will be that both reactants are present in sufficient concentrations to drive the reaction forward. Remember that the full haloform reaction is no longer an equilibrium process; each bromination and the final separation is a non-reversible step; see $(3)$.

$$\begin{gathered}\ce{RC(-O^-)=CX2 + Br2 -&gt; RC(=O)-CX2Br + Br-}\\[0.8em]
\ce{RC(=O)-CBr3 + OH- &lt;&lt;=&gt; RC(-O^-)(-OH)-CBr3} \\[0.4em] \ce{-&gt; RC(=O)-OH + CBr3- -&gt; RCOO- + HCBr3}\end{gathered}\tag{3}$$

The mere presence of non-reversible steps will drive any reaction forwards.