Store bought cake can safely be kept out at room temperature for 2 to 3 days before it starts to mold and go bad.
You can however keep the cake a bit longer in the refrigerator but it's best to use the cake within 1 week to avoid it going stale and possibly going bad.
If you do refrigerate the store bought cake make sure to remove the cake from the refrigerator at least 30 minutes prior to serving it or eating it.
The 30 minutes will allow the cake enough time to warm up to room temperature so it won't be as cold when eating it.