We have a weekly stored procedure that ocassionaly picks up wrong execution plan that causes much longer execution times.
I've tried to force correct execution plan but still every few weeks the execution plan forcing fails with following error:
Query processor could not produce query plan because USE PLAN hint contains plan that could not be verified to be legal for query. Remove or replace USE PLAN hint. For best likelihood of successful plan forcing, verify that the plan provided in the USE PLAN hint is one generated automatically by SQL Server for the same query.
Sometimes even after such error the good execution plan is created and used (see following screenshot) 
The good execution plan: https://www.brentozar.com/pastetheplan/?id=B1NIXXohp
Slow execution plan: https://www.brentozar.com/pastetheplan/?id=Sy3fmmjnp
Query itself is visible in the plans (tried to insert it here but it gets strange formating).
When I implemented the index suggested by the second plan:
Cannot insert duplicate key row in object 'MEX.Agreement_Transaction_Table' with unique index 'IX_AgrTblIncludes'. The duplicate key value is (202304, 1, 0, 0xa0be430067091800).
What could be the reason of picking wrong plan/plan forcing failures?