SQLite documentation states that foreign key constrains check is disabled by default (source: https://www.sqlite.org/foreignkeys.html; second paragraph of the "Overview" section).
Furthermore, if we check the framework's database configuration file (config/database.php), under the sqlite connection options, the default option to check for FK constrains is activated by default, unless stated otherwise via its environment variable.
That's why you get different behaviors when running the query via the framework vs directly into sqlite.