The intramuscular antipsychotics are formulated as esters, which means a fatty acid is attached to the molecule to slow its absorption. This, combined with the large doses administered and the already fairly long duration of action of some of these compounds, means that a single injection can last a very long time.
You could do a similar thing with morphine but it isn't really potent enough for it to make sense. However similar types of long-acting formulations of intramuscular opioids do exist, for example sublocade (a long-lasting shot of buprenorphine -- which is used as an alternative to daily suboxone add a fatty acid to fentanyl to create a shot