As others have noted, you cite the source that you actually used. If A quotes or describes B, and you have read A but have not read B (whether because it's not available, you just didn't bother, or whatever), then you cite A.
It is generally considered better to go to original sources. If some later writer says that Aquinas said sex with a pregnant woman is a sin -- and let me interject here that I have no idea what Aquinas said on the subject, I've read pieces of the Summa but I've skipped many pieces too -- the later writer may be misquoting Aquinas or applying his own interpretation to something ambiguous. If you were to say, "Aquinas said X" because some other writer claims he said X, that would simply be wrong. Especially if the writer did not give the exact quote, but even with an exact quote, you could be missing the context.
So if your point is to say, "this is what Aquinas" said, you should go to the source and read and quote (and cite) Aquinas. It's easy enough to get copies of Aquinas on the web these days. If your point is to say, "this is how so-and-so interprets Aquinas", than you should quote (and cite) so-and-so.
Some writers will give a citation like, "Aquinas, as quoted in ...". This is a reasonable thing to do if the original source is difficult to obtain. Like if he's quoting a book that is no longer in print and you can't find a copy. It's most clearly valid if the original book no longer exists, like if you're quoting a book written in AD 300 that quotes an earlier book and that earlier book has been lost to history. But for something easily available like Aquinas, for a scholarly paper I'd just get the original.