Cheese is a network of proteins holding fat and water. When you heat it, the fat melts first. If the heat is too high or comes too fast, the proteins tighten up and squeeze out the fat and water, and you get an oily pool with rubbery clumps.
Why some cheeses do it more: as cheese ages, its proteins break into smaller pieces, so the network is weaker and holds less fat. That's why a sharp, aged cheddar tends to "oil off" more than a young mozzarella. Higher-fat cheeses also have less protein to hold everything together.
How to fix it:
- Melt low and slow, and stir gently. Don't let sauces boil.
- Grate the cheese first, so it melts quickly and evenly.
- Toss it with a little cornstarch before melting if you're making a sauce. It helps hold everything together.
- Mix cheeses. Use an aged cheese for flavor and a younger, higher-moisture one (like mozzarella or young Gruyère) for a smooth melt.
- Try sodium citrate. A pinch of this emulsifying salt, available online, lets a natural cheese melt as smoothly as processed cheese.
The same rules apply to fondue, so see What cheese is best for fondue? for a version that holds together.
Related: What cheese is best for fondue? Can you make it without wine? · What is processed cheese? · Is pre-shredded cheese as good as block cheese?