Which grammatical rule is being used here?
&quot;得&quot; in &quot;考试考得不好&quot; is a &quot;degree/result complement&quot; that indicates 'the degree' of a verb, or 'the result' of a verb

考试考得不好 = [考试(to take exam) - 考得 take exam to the result of - 不好(not good)]

or

考试考得不好 = [考试(to take exam) - 考得 take exam to the level of - 不好(not good)]

More detailed example:

考试考得不好，祇得到  D 平均 - the result of the verb was bad)
考试考得很吃力 - the degree of the verb 'taking exam' is at the degree of 很吃力 (laborious level)

Side note: 得/不 as potential complement:
考得好试 = able to take exam well
考不好试 = unable to take exam well