How can I get the latest five scores per user per subject?
Do you want the ones with less than 5 scores in mix.  If you want only the 5 scores one, you can add a having to your query:

    SELECT user_id, round(avg(score)::numeric, 2) AS sc_avg, dept
    FROM  (
       SELECT *
             ,row_number() OVER (PARTITION BY user_id, dept ORDER BY cdatetime DESC) AS rn
      FROM mg.scores
      WHERE score IS NOT NULL) as score
       ) AS x
    WHERE  x.rn &lt;= 5
    GROUP  BY user_id,dept
    HAVING count(*) &gt; 4;