The reason why coffee tastes bad when you're sick is because your sense of taste and smell is altered significantly when you're sick.
When you're sick your sense of smell and state is altered due to inflammation in your nasal passages caused by a cold, flu or other illness.
This makes it harder for you to perceive the usual flavors of coffee properly and is often described as dysgeusia.
Dysgeusia can make even familiar foods and drinks including coffee taste different.
When you're sick your body also produces inflammatory proteins that can affect your taste buds and potentially make you more sensitive to bitter tastes such as those found in coffee.
Sickness can also cause dehydration and can further impact your taste perception and make coffee seem harsher and taste bad.
When I'm sick I also avoid drinking coffee and instead switch to hot tea.
Coffee I really love but not when sick.
I usually wait at least a few days after the sickness or flu is over and then I start to drink coffee again.