Different plans for the same SQL code
This is called parameter sniffing, and it's one of the hardest problems to solve in a database.

The basic problem is that data is skewed in a way that makes the cost based optimizer choose different plans for returning your data.

There are a lot of ways people think they "fix" parameter sniffing:


Recompile hints
Optimizer for unknown
Optimize for a value


But these really just disable parameter sniffing in different ways. That's not to say they can't solve the problem, they just don't really get to the root cause.

That's because getting to the root cause is usually kind of difficult. You have to look for those pesky "plan quality issues".

Starting with the fast vs slow plans, look for differences like:


Indexes used
Join order
Serial vs Parallel


Also look for different operators that make your code sensitive to parameter sniffing:


Lookups
Sorts
Join type
Memory grants (and by extension, spills)
Spools


Don't get too wrapped up in seek vs scan, index fragmentation, or any of the cargo cult-y stuff people hem and haw about. 

Usually, there's a pretty basic indexing problem. Sometimes the code needs a little rewriting. If you want more help, please share the query plans, along with the code, table and index definitions. 

Otherwise, good luck!