Some cake recipes calls for rum, and there is none available. How to substitute? If possible, it should be non-alcoholic.
Also, what is its role in baking or cooking?
The most accurate substitution would simply be rum extract. It is concentrated rum with a huge kick of flavor, and much less alcohol. A little goes a long way.
If you're avoiding liquor, then you may be able to use vanilla extract. Non-alcoholic varieties are available. According to Ochef you can also use molasses thinned with pineapple juice.
The rum is used simply for flavor.
Apart from flavour, spirits can play another role: adding temporary moisture that can be useful in the mixing process. Spirits add water and alcohol, which allows you to mix the ingredients, but the alcohol will evaporate in the oven, so the baked dessert will not have all that moisture.
I read a recipe in Cooks Illustrated where they replaced water with vodka to get a better dough for pies, but I never used that for cakes.
If the texture of the cake without rum works, you need it only for flavour, you can use another spirit or spice for that.
Unless your recipe includes the word 'flambe', its role is purely flavour and nothing more. As rum is derived from sugar, you could--bearing in mind the other aspects of your recipe--substitute molasses, caramel, or just leave it out.