Creating Multiple Tables with WITH statements
You try to use table1 and table2 before their creation... reorder tables in WITH clause.

WITH table1(c1, loc1) AS (SELECT character1, location 
                          FROM lotrfirstencounters),
     table2(c2, loc2) AS (SELECT character2, location 
                          FROM lotrfirstencounters),
     table3 AS (SELECT c1 as c3 
                FROM table1 
                union all 
                SELECT c2 
                FROM table2)  

SELECT DISTINCT * 
FROM table3 
ORDER BY c3;