If intermediate goods produced and sold during the year are not counted toward the current year GDP, then why are intermediate goods produced but NOT sold during the current year counted toward the current year GDP?
This happens because of the way we measure investment. In particular, how we measure changes in business inventories. When an intermediate good is produced, but not sold, it is added to inventory. This change in inventory is recorded in GDP as a change in inventory under investment. The next year, when it moves out of inventory and into a final good, it is subtracted from change in inventory under investment. The net effect it has is zero, but it needs to be accounted for the year it is produced.
Let's consider a tangible economic example. Imagine a tire as an intermediate good for the production and sale of a car. If the tire is produced this year, but not sold, it enters the GDP as a change in inventory. However, the next year it is used in a car that is sold, and the car is counted towards GDP. At this point the tire is double counted, but at the end of the year, we look at the change in business inventories, and we have one less tire, which gets subtracted from GDP. So in the end, we still only count the value of the car, but part of its value was counted in the previous year (because of inventories).
There are two reasons why this is done this way. The first is that we do not want to double count production, which is why intermediate goods are not counted in GDP estimates. If we counted both the tire and the car, we would be double counting the tire because the value of the tire is already in the car. However, when a business has inventory, it is very difficult to distinguish between intermediate and final goods, so economists look at the value of total inventory. Since inventory is a stock and can change up or down over time, this is fine, because intermediate goods can join inventory one year (a positive contribution to GDP) and leave inventory the next year (a negative contribution to GDP).