Perhaps check and see if the portal on the details tab has been inadvertantly given the same object name as the payments portal.
Have you used the Script Debugger and followed the script as it executes step-by-step by clicking the "Step Into" button? At what point in the script does it switch to the details tab?
If this is creating a new record in the portal, you may well be better off not to have your script interact directly with the portal. Instead, use this type of script:
Set Variable [$InvoiceID ; Invoices::InvoiceID ]
Set Variable [$amt ; Invoices::gAmt ]
Go To Layout ["InvoicePayments" (InvoicePayments) ]
Set Field [InvoicePayments::PaymentID ; $PaymentID]
Set Field [InvoicePayments::InvoiceID ; $InvoiceID ]
Set Field [InvoicePayments::Amt ; $Amt ]
Go To Layout [Original Layout]
Note that I've assumed a few things that may not exactly match your setup and field/layout/table names, but you should be able to adapt the approach to get it to work for you.