Certificates have lots of metadata, like "Basic Constraints" (BCs), "Key Usages" (KUs), "Extended Key Usages", and "Certificate Policies" that specify what they are allowed to be used for (the reason there's so many things is that the X.509 standard has been extended many time, and some implementations only understand some parts of it or want the more specific values if available). These are part of the certificate signing request (CSR) sent to the CA, and are part of the resulting certificate.
For example, if you look at the cert for this site, you'll see that its BCs specify that it is not a CA, and its KUs are digital signature and key encipherment (both used for the server side of the TLS handshake, in some cipher suites). It also has some additional EKUs and other fields, but for the moment those aren't important to the question. If you instead look at the root CA for this site, it's quite short, with only the BCs specifying that it is a CA, and KUs including Certificate Signing and CRL Signing. If you check the intermediate CA, you'll see that it's also a CA cert according to its BCs, and allowed to sign certs and CRLs according to its KUs.
It is the responsibility of the CA to not issue a CA-usable certificate to any party that isn't authorized to act as an intermediate CA under you. In other words, the CA parses the CSR, makes sure that it doesn't specify BCs or KUs that allow it to act as a CA (or, if it does, that it's from a party trusted to act as a CA), and issues the certificate or not accordingly.
It's also essential that the TLS client library, when validating the certificate chain, verify that everything acting as a CA is allowed to do so. It turns out that this wasn't always done, even in widely used SSL/TLS libraries like OpenSSL and SChannel (the Microsoft library built into Windows). Security researcher Moxie Marlinspike wrote a paper about this, and a tool to exploit it; the paper seems hard to find now, but you can view his 2009 presentation deck from BlackHat (or possibly DEFCON) on the topic here: https://www.blackhat.com/presentations/bh-dc-09/Marlinspike/BlackHat-DC-09-Marlinspike-Defeating-SSL.pdf. Quite informative.