You are correct. U.S. nationals, including U.S. dual nationals, are generally required to use a U.S. passport when entering and leaving the United States. This requirement is based on U.S. law.
However, U.S. dual nationals may also hold a passport from another country (such as Canada in the context of the original question). While entering or leaving the United States, they are allowed to use their U.S. passport. Still, they may be required by the country of their foreign nationality (e.g., Canada) to use that country's passport when entering and leaving that foreign country. This means that when traveling to Canada, for instance, a U.S. dual national should use their Canadian passport, and when traveling to the United States, they should use their U.S. passport.
Using the foreign passport to travel to or from a country other than the United States is generally not inconsistent with U.S. law. The key is to comply with the entry and exit requirements of both countries you are traveling to and from, using the respective passports as required by each country's laws and regulations. It's essential for dual nationals to be aware of the specific requirements of both countries to avoid any issues while traveling.