You don't have an 'unusual' doubt; you are simply confusing matter waves with electromagnetic waves, which stymies many readers at first. Louis de Broglie proposed in 1924that all matter exhibits wave-like behavior, with a wavelength given by (to use your notation) $\lambda_B = h/p$ where $p$ is the matter's linear momentum.
Conversely, electromagnetic radiation behaves like it is composed of tiny corpuscles called photons, each of which carries a certain quantum of energy, given by $E = h \nu$, where $\nu$ is the frequency of the radiation. Expressing $\nu$ as $\nu = c/\lambda,$ we find that $E = hc/\lambda,$ which you mention in your question.
In other words, $\lambda_B$ and $\lambda$ are two completely different kinds of wavelength: the former relates to moving matter, whereas the latter, to photons.
Your teacher's approach at deriving de Broglie's relation is either incorrect or incomplete. The relation $E = mc^2$ uses the invariant mass of massive objects, so equating that with $hc/\lambda,$ which is valid only for photons, suggests that photons have mass, which is emphatically wrong.
What your teacher was perhaps trying to do was assume that all the matter in a given mass $m$ got converted into pure electromagnetic energy (say, through nuclear fission) and then calculate the wavelength of the ensuing photons with said energy. In that case, the derivation is justified until the generalization $c \to v,$ which requires much more clarification, if it is not outright wrong: so far we have only mentioned photons, which always move at the speed $c$.
Either way, simply equating two similar-looking expressions at face-value is a dangerously unsound way to teach Physics.