• It's likely this code

    and (cte2.Disposition_Code_Txt in ('PA','PM','NP','CI','CR','CL') and cte2.rn=2)

    The row number in the CTE is just based on loan number so it's likely the loan with the PM code is not getting assigned to row number 2. Do you have a more granular field you can use to determine the order of the records, if you just have date and both loans happen on the same day the order that the loans show up in will be ambiguous.