If there were no valve in the line, then when the pump is off, liquid may siphon from the higher container to the lower container until the liquid level is equal in each container.
Some pumps might prevent this by offering no free path for liquid to flow and preventing their internal parts from turning backwards by friction. For example, a screw pump. However, a centrifugal pump is probably more common, and in these, there is nothing preventing the flow of liquid in either direction when the impeller is not turning. Even when the impeller is turning, liquid can flow backwards if the external pressure is enough to overcome the pressure difference generated by the pump.
A solenoid valve solves this problem, and unlike a pump, is designed to block the flow of liquid at some pressure.
A check valve is another solution. However, to open a check valve requires some mechanical work, reducing the efficiency of the pump. Even when open, a check valve introduces more fluid friction than a solenoid valve.
There is an electrical analogy to this dilemma: active rectification. This is when an active device like a MOSFET is used in place of a diode. Whereas a diode has a forward voltage of typically 0.65V, a properly selected MOSFET can have a forward voltage of some mV. This in turn reduces losses in the rectifier. The tradeoff is increased parts cost and complexity.