Is the primary on a loan obligated to pay back a cosigner if the cosigner pays off the loan without the knowledge of the primary?

YES !!! He/she should certainly discuss it with the cosigner. It may be a gift or it may just be that the cosigner doesn't want to have that note appearing on his/her credit report. Whatever the reason, even if the cosigner did it as a gift, the primary should acknowledge and express appreciation. But be prepared if the cosigner expects the loan to be paid back.