Should I take the cake out of oven immediately after it is baked or leave it in oven for some time
Most cake recipes I have seen give an approximate baking time and also instructions for determining doneness by observation (the "toothpick comes out clean" sort of guideline). When the criteria for doneness are met, it is assumed you will take the cake out of the oven immediately. 

Very often there are further instructions about cooling, removing from the cake pans, frosting, etc. But they don't expect you to leave the cake in the oven (whether turned "off" or "on") past when it is done. Leaving it in the oven while the oven is cooling down would just introduce too much variability as ovens would cool at different rates.

I agree with your speculation that cake problems must be from some other cause.