The link is a rule
A foreign key is a column that must match a value in another table. It is how split tables stay connected without drifting apart. Declare it with REFERENCES and the database enforces it on every write, so a join can never meet a row that points nowhere.
sqlite is strict about it
sqlite will not let you create a table whose foreign key points at a table that does not exist yet, and it wants the referenced column to be a primary key. That ordering is a trap: create the table you point at first, then the one that points to it. Plan the order of your CREATE statements and the rest follows.