Why is machine built this year but not sold this year included in GDP? GDP is the sum of market value of all final goods in the current year, so why is is machine built this year but not sold this year included? In addition why is machine not built this year but sold this year not included in GDP?
The comment provided by @Kitsune Cavalry:


  It counts as investment. Inventory, capital, and structures are part of investment. Unsold stuff counts as inventory.


is correct as to the accounting; let me provide a little more intuition to it. 

GDP measures production (output), not sales— it is in the name: Gross Domestic Product. And for many firms, production into inventory, making a thing with the explicit intent of building inventories so that the thing is available for purchase when people want that thing, is a core part of the business. 

Imagine a firm that makes snow throwers— they build these machines year round, then basically sell all of them during a period from late fall through mid-winter (the exact seasonal pattern doesn't matter, only the fact that there is one). 

For the purpose of counting that firm's output in GDP, it should be clear why we want to recognize that they produced snow throwers all year, rather than having all that production only show up during the few months when the machines are actually sold. 

This approach isn't without its downsides— in the event that large volumes of production into inventory occurs because demand for the product in question has fallen off permanently, then the market price of the units sold will have been applied to a bunch of units that would never have sold at that price, and the value of output will be biased. This bias is of smaller magnitude than the mis-measurement that would be introduced by normal inventory fluctuations if we were only to count output when products are finally sold, though, so we live with it.