When you run separately, they are run in two batches. It may be that when you run them together (which is in a single batch), the query plan is different.
Examine the query plans in both cases and see if the combined plan is equivalent to the plans for the two-step execution stacked together. Also, in the single query plan, see which steps take long time. For those steps that consume long time, add a statement level recompilation hint. for example if it is an insert statement
INSERT INTO TheTable (col1, col2) values (1,2) OPTION(RECOMPILE)