The court said this would create "unfettered discretion" for the San Francisco-based bank to reject modifications "for any reason whatsoever—interest rates went up, the economy soured, (or) it just didn't like the borrower."
While a federal appeals court in Chicago reached a similar conclusion last year, the 9th Circuit decision applies in several western U.S. states—among them California, Arizona, and Nevada—that have been particularly hard-hit by foreclosures.
Wells Fargo said it had $352 million of loans under HAMP in a trial modification period as of June 30.
(Read more: Bank of America Paid Bonuses to Foreclose: Lawsuit)
"The 9th Circuit did not rule on the merits of the underlying cases, and found only that the district court should consider the arguments put forth by the plaintiffs," the bank said in a statement. "Wells Fargo has strong defenses to those arguments, and is prepared to present its case."
'Heads I win, tails you lose'
Unveiled by the Obama administration in 2009, HAMP pays mortgage lenders and servicers to rewrite loan terms for borrowers who cannot afford their payments.
While steps have been taken to broaden HAMP's reach, fewer loans than expected have been modified, and both Democrats and Republicans have complained that many borrowers who get help default on their modified mortgages.
The program has also spawned other litigation, and the 9th Circuit said it "seems to have created more litigation than it has happy homeowners."
In a separate lawsuit in Massachusetts, homeowners accused Bank of America Corp of offering employees financial incentives to stall HAMP applications because foreclosures or in-house loan modifications could be more profitable.
A judge is considering whether to make that case a class action.
One of the Wells Fargo cases was brought by Phillip Corvello, who claimed he complied with a written trial period plan for a HAMP modification, and the other by Jeffrey and Karen Lucia, who claimed to comply with an oral plan.
The Lucias' home was sold at foreclosure in August 2010, but they kept possession of the property, Wells Fargo said.
Both the unsigned majority opinion and a concurring opinion by Circuit Judge John T. Noonan faulted Wells Fargo's drafting of the trial period plan, saying that to rule in the bank's favor would render the benefits for borrowers illusory.
"No purpose was served by the document Wells Fargo prepared except the fraudulent purpose of inducing Corvello to make the payments while the bank retained the option of modifying the loan or stiffing him," Noonan wrote. "'Heads I win, tails you lose' is a fraudulent coin toss. Wells Fargo did no better."
The case is Corvello v. Wells Fargo Bank NA et al, 9th U.S. Circuit Court of Appeals, No. 11-16234.