If website B
sets a cookie on your website A, then it'll be considered a third party cookie for website A
, It's quite simple.
Secondly, cookies are set by servers, so it may not be right to say "Website B has cookies", Probably you mean to say that Websites B sets some cookies, and Website A sets some cookies on client.
So, if website A contains an ad that is served by website B, then
website B can set a cookie in your browser. For example, maybe website
A uses <iframe src="http://websiteB.com/ad.html> to serve the
ad from website B. Then when your browser goes to fetch
http://websiteB.com/ad.html, the response will come back with a
Set-Cookie header that sets a cookie with some unique random string.
If website C also includes an ad from website B, then that unique
cookie will be sent when the ad on website C is fetched from website
B.
Here's this question with very detailed answer