Combining 2 SELECT queries and printing the results in PostgreSQL
The primary solution is to add parentheses:

(  -- parentheses required!
SELECT dt1.name AS name1, dt1.time AS time1
     , dt2.name AS name2, dt2.time AS time2
FROM   departure_times dt1
JOIN   departure_times dt2 USING (tram_id)
WHERE  dt1.name = '$name'
AND    dt2.name = 'CitySquare'
-- no ORDER BY?
LIMIT  5 
)
UNION ALL  -- see below
(
SELECT dt1.name, dt1.time, dt2.name, dt2.time  -- see below
FROM   departure_times dt1
JOIN   departure_times dt2 USING (tram_id)
WHERE  dt1.name = 'CitySquare'
AND    dt2.name = '$name2'
-- no ORDER BY?
LIMIT  5
);


Without extra parentheses LIMIT is only allowed once at the end of the query and applies to the result of the UNION. To attach a LIMIT to each SELECT parentheses are required.

The manual:


  The UNION clause has this general form:

select_statement UNION [ ALL | DISTINCT ] select_statement

  
  select_statement is any SELECT statement without an ORDER BY, LIMIT, FOR NO KEY UPDATE, FOR UPDATE, FOR SHARE, or FOR KEY SHARE clause. (ORDER BY and LIMIT can be attached to a
  subexpression if it is enclosed in parentheses. Without parentheses,
  these clauses will be taken to apply to the result of the UNION, not
  to its right-hand input expression.)


Other notes:


I switched to UNION ALL - assuming you don't actually want to try and fold duplicate rows.
Names of result columns are determined by first SELECT of a UNION query. Names (or aliases) in all following SELECT statements are ignored.
You may want to add ORDER BY to each SELECT. LIMIT without prior ORDER BY returns an arbitrary selection that can change with every execution - in simple queries determined by the physical order of rows in the table (or in the index), which can change any time.