Federer, 37 and bidding for his 101st career title, received a walkover into the final, where he will play Dominic Thiem, a 7-6(3) 6-7(3) 6-4 victor over Milos Raonic in Saturday's only semi-final.
It would have been the first meeting between the pair since 2017.
"I warmed up today and I felt that my knee was not good to compete at the level I needed to compete in semi-final," Spain's Nadal said in a statement.
ATP Madrid
Zverev downs Berrettini to clinch second Madrid crown
9 HOURS AGO
"It's tough for me to accept all these things that I'm going through in my career."
The knee had begun to bother him in the second set of his 7-6(2) 7-6(2) victory over Karen Khachanov in the quarter-finals on Friday.
Nadal had enjoyed a dominant week at Indian Wells, reaching the semi-finals without dropping a set.
"For me it is not about today only," the world number two said.
It's about what it means for me to have to pull out in a tournament that I love so much like this one, and in the semi-finals after playing well during the whole tournament. You can imagine that I can't be happy.
Tennis
Osaka says risk of staging Olympics must be carefully weighed
12 HOURS AGO
ATP Madrid
Zverev puts on Madrid masterclass to down Thiem in semis
YESTERDAY AT 17:11