Every real heat engine takes in heat from a hot source, converts part of it to useful work, and must dump the leftover heat into a cooler sink, it can never turn every last unit of heat into work with nothing wasted. If it could, we would have a machine running forever off a single heat reservoir with no waste, which the second law forbids outright. Ice melting at 0 degrees and gas expanding freely into empty space both happen naturally and raise the system's entropy, which the second law fully permits, and a reversible adiabatic expansion is an idealised but allowed process. So the one truly forbidden case here is turning heat completely into work.