Postgres: What could cause the error "cannot call populate_composite on a scalar"?
Unrelated, but: you can simplify your query to:

SELECT x.*
from the_table, 
     jsonb_array_elements(jsonbrecords) AS t(doc),
     jsonb_to_record(t.doc) as x ("grade" text, "userId" text, "endYear" int, "startYear" int);


Now for the actual question. The error can be avoided by not using jsonb_to_record and accessing each key individually instead:

SELECT t.doc -&gt;&gt; 'grade' as "grade",
       t.doc -&gt;&gt; 'endYear' as "endYear", 
       t.doc -&gt;&gt; 'startYear' as "startYear",
       t.doc -&gt;&gt; 'userId' as "userId"
from the_table, 
     jsonb_array_elements(jsonbrecords) AS t(doc);


You don't really lose flexibility as you need to specify the column list with jsonb_to_record() as well. 

Online example: http://rextester.com/VVGJ34083