Why is it necessary to keep electrodes apart during electrolysis? The only reason i think of is to be sure that the products do not come into contact with each other. Could you please help me to understand it in more detail.
You pretty much have it right there.
You don't want the products you are getting to immediately react with each other, as that would defeat the whole purpose of the electrolysis. It can also be VERY dangerous if the products interact. (Such as the electrolysis of molten sodium chloride, or hydrogen fluoride). Also, if the two electrodes are physically touching each other, that will complete a circuit and no electrolysis will occur because the ions in solution will not be part of the circuit.