What are the SET options that affect Plan Reuse and how to get their values in T-SQL?
If it's a case of different options causing different plans to be used, just check the options using sys.dm_exec_plan_attributes. If the options are not the same for a good and a bad plan, that can then be the reason.

A list of plan cache keys can be found in the following answer by Martin Smith:

What would cause parameter sniffing one one computer and not another?