When fats and oils are oxidized, they become rancid and their smell and taste change. This process is known as rancidity.
Some stale food give a bad taste and a bad smell because of rancidity. Rancidity is a phenomenon in which the fats present in food get oxidised due to the oxygen present in atmosphere.
Rancidity-Change in smell of food item containing fat and oil when kept open for longer time due to oxidation is called rancidity. To prevent rancidity, food items are flushed with nitrogen or kept in airtight containers.
Rancidity refers to the spoilage of a food in such a way that it becomes undesirable (and usually unsafe) for consumption. In other words, it is a process which causes a substance to become rancid i.e. develop an unpleasant smell or taste.
These were all the answers that I could find on Rancidity on the portal.
the summary is that the oil in the oily food gets oxidised, due to the oxidising agents present in the atmosphere, and leads to the change in smell and taste of it.