Why do water and oil (a long-chain hydrocarbon) not mix?
Because the interaction between oil and water molecules is insufficient to overcome the interaction between water and water and oil and oil molecules.
A general rule of which you have heard is
In a related context, we could consider the solubility of alcohols with water. Both methanol and ethanol, short chain alcohols, are infinitely miscible with pure water. For propanol and beyond, water solubilities decrease markedly, and again this is attributable to interactions between the hydrocarbyl chains of the alcohols.