The pen is the passive subject in «كُتِبَ الدَّرْسُ بِالْقَلَمِ».

Mafʿūl Mā Lam Yusamma Fāʿiluhu — The Passive Subject