If the object of mass $m_1$ comes back in the opposite direction with the same speed it hit the other object, then the total kinetic energy of the system after the collision is:
Actually, this is not correct. Unless $v=0$ of course (which it would be for example when a ball hits a stationary wall). It is not possible for the object to bounce back with the same speed if the other object starts to move as well. They must share the energy present.
Otherwise, as you are pointing out, there is more energy in the system after than before. Some energy must have come into existence suddenly, which is impossible (from the energy conservation law) - energy must come from somewhere, so if it is not added to the system from the outside or from the inside (from fuel or deformations or alike) then the total energy in this system can't increase.
Edit - for the inelastic collision
For an inelastic collision, the difference from the above explanation is that there is energy added (or removed) to the system.
- When two cars crash, energy is absorbed to deform the metal. Total energy that goes as kinetic energy reduces.
- When two cars crash and one's fuel tank explodes, energy is absorbed to deform the metal but also much energy is released from the chemically stored energy in fuel. More energy is now going as kinetic energy than before the impact.
So, if you of some reason has a case where the speed of one object just before impact happens to equal it's speed right after impact, then the released energy just happens to be just enough for this to be equal. Had a tiny bit more energy been released/given to the system, then the speed might have been higher than before impact.