Electrons are quantum mechanical entities, and interact quantum mechanically with the environment. This means that there are differential wave equations, whose solutions control the probability of how an electron will interact . Probability means that an accumulation of the same boundary condition events should be made, in order tos see an effect.
In the double slit case , the boundary conditions are "electron falling on double slit given distances separation and width of slits". This is controls the boundary conditions that choose the particular wave-function solution. It becomes a different experiment if the electron is disturbed in order to detect which slit it went through, different boundary conditions and thus different wavefunctions .
In different words, in order to detect an electron, an interaction has to happen, all interactions disturb the original boundary conditions, and a different wavfunction will control the track of the electron destroying the coherence needed in order to sum many electrons with the same boundary conditions.