"How many pineapples do they have?"
Translation:Kiom da ananasoj ili havas?
Why isn't pineapple in the accusative case if it's "being had"? Could you say "Kiom da ananasojn havas ili?" ?
Because it's the complement of the preposition "da", and prepositions (in general) don't take the accusative case after them.
And no, you couldn't say "da ananasojn" in any situation (but "Kiom da ananasoj havas li" would be fine, and could only mean "How many pineapples does he have" -- "How many pineapples have him" would be "Kiom da ananasoj havas lin").
Could the sentence be written ¨kiom da ili havas ananasoj?¨ I ask because in that case, wouldn't the word have to be 'ananasojn' instead?
"Kiom da ili havas ananasojn?" = How many of them have pineapples?
Not the same meaning as "How many pineapples do they have?"
Also note that while some people treat "kiom da" as a unit, it's not -- it's "kiom" + "da", and since the latter is a preposition, it has to stand in front of something.
For example, if someone is standing at your market stall, admiring your pineapples, you can't ask, "Kiom da vi volas?" for "how many do you want?" -- it either has to be "Kiom vi volas?" or "Kiom da ananasoj vi volas?".