How can I dynamically distinguish between categorical data and numerical data?
I'm not aware of a foolproof way to do this. Here's one idea off the top of my head:


Treat values as categorical by default.
Check for various attributes of the data that would imply it is actually continuous. Weight these attributes based on how likely they are to correlate with continuous data. Here are some possible examples:


Values are integers: +.7
Values are floats: +.8
Values are normally distributed: +.3
Values contain a relatively small number of unique values: +.3
Values aren't all the same number of characters: +.1
Values don't contain leading zeros: +.1

Treat any columns that sum to greater than 1 as being numerical. Adjust the factors and weights based on testing against different data sets to suit your needs. You could even build and train a separate machine learning algorithm just to do this.