There are no restrictions on passing through immigration during a connection / layover. As long as you have the necessary visa or are visa free, immigration won't look twice.
Another thing that hasn't been mentioned above are immigration queue times. Visitor queues have looked absolutely dreadful for the past three weeks at HKIA as this is peak season. Depending on your arrival time and what other planes have just arrived, you could be in for an unpleasant wait. And FYI departure visitor queues aren't nearly as bad...