The station will attack you when you have been scanned by the patrolling cops and found to have a bounty on you, illicit cargo or a criminal passenger on board. If You have any of those things, you have to get into the station without getting scanned. That means flying in fast and straight down the stations axis into the slot. You don't need to boost, just use 4 pips to engines and back off just before you go through.
If the station is hostile, it'll be marked red, so pretty obvious that something is wrong. In 6000hrs playing and doing lots of naughty things, I've only ever seen that twice.
Other reasons the station blows you up are pretty obvious, like going in without docking permission, exceeding the loitering time-out, shooting inside the station,etc.
I would bet 100/1 that you were blown up because you were scanned and found to be a criminal because of your bounty. You can easily find out by checking your log files. Find the one for that session, open it with Notepad and search for "Died". The comments recorded before that will show why they shot at you. Everything is recorded!