Is this an exception to the rule that strong acids/bases always replace weak acids/bases? According to the $\mathrm{p}K_\mathrm{a}$ table: hydrochloric acid is stronger than sulphuric acid. It has a $\mathrm{p}K_\mathrm{a}$ around $-6.3$ while the $\mathrm{p}K_\mathrm{a}$ of sulfuric acid is around $-3$. The second dissociation in the case of sulfuric acid is not very extensive and doesn't contribute much to its acidity.

\begin{aligned}
\ce{H2SO4 + H2O ~&amp;&lt;=&gt;~ H3O+ + HSO4^{−}&amp;&amp;pK_{a}~=~-3}\\
\ce{HSO4- + H2O ~&amp;&lt;=&gt;~ H3O+ + SO4^{−2}&amp;&amp;pK_{a}~=~2}\\
\ce{HCl + H2O ~&amp;&lt;=&gt;~ H3O^+ + Cl^{-}&amp;&amp;pK_{a}~=~$-6.3$}\\
\end{aligned}

Now $\ce{BaSO4}$ reacts with  $\ce{HCl}$ to produce very less of $\ce{BaCl2}$ because of the insolubility of $\ce{BaSO4}$.

My teacher told me that in a reaction "Strong acids or bases replace weak acids or bases". This holds good for this reaction as $\ce{HCl}$ is stronger than $\ce{H2SO4}$.

However $\ce{NaCl}$ reacts with $\ce{H2SO4}$ to produce $\ce{Na2SO4}$ and $\ce{HCl}$. In this case $\ce{H2SO4}$  replaced a stronger acid $\ce{HCl}$. How do we account for this?
Every reaction is considered reversible to some extent and feasibility of a reaction is mainly dealt in the terms of favourability of either products or reactants. When we say that creating a weaker acid from a stronger base is feasible, we actually mean that the equilibrium favours the formation of the products in such a case. However some other factors can be at play and can well influence an equilibrium. One such governing principle is Le Chatalier's.

$$ \ce{H2SO4 + 2NaCl &lt;=&gt; 2HCl + Na2SO4 }$$

Here's a youtube video showing the production of hydrochloric acid under laboratory conditions. Notice the $\ce{HCl}$ produced is a gaseous product, and hence there's an imbalance in our equilibrium; $\ce{HCl}$ escapes out as vapors from the solution, lowering $Q_c$ of the reaction thus making the reaction go forward.