I wonder why the family also married their uncles and nieces that sounds near to incest no wonder some of them had something wrong with them
Wasn't Marghareta of Austria also the aunt of her husband Philip III?
Margarita of Austria was not Philip's aunt, but his cousin. Their respective grandparents, Emperor Ferdinand I and Emperor Charles V were brothers.
Maybe you're confusing King Philip III's wife with another Margarita of Austria, who was indeed Philip III's aunt. She was the youngest sister of the King's mother, Anne of Austria, and was a nun in Madrid.
Why did the family members marry among them? It wasn't for pleasure or love, but for political reasons. They wanted to keep their inheritance from rival dynasties (Bourbons, etc), so they began to intermarry more and more frequently among themselves. It's ironic that eventually this inbreeding brought the extinction of the male line of the Habsburgs and their inheritance passed to the Bourbons, which was what the Habsburgs feared and wanted to avoid!