You can't use an actual tab for the same reason you said above. StackExchange sites function like most other sites as opposed to a code editor so Tab behaves like it should. You have to use spaces but not the normal ones as SE will ignore whitespace for the most part and 4+ spaces triggers a block of code in markdown.
I actually have two spaces here. (click edit on this answer to check)
# and the four spaces before this have made it into code..
So, one way you can achieve this is by using html, as obviously, SE supports a subset.
to get a space. Join more together for more space(s).
is the entity used to represent a non-breaking space. It is essentially a standard space, the primary difference being that a browser should not break (or wrap) a line of text at the point that this occupies. (src)
Two space indentation
Four space indentation
Eight space indentation
Also, there is a user script on stackapps that might be of some interest if you really need this to work.
This user script changes the behavior of a few keys (most notably the Tab key) within the post editor to behave more like it does in IDEs or text editors: