I asked about this issue to Autodesk Support and I was able to get an answer.
The problem was because I imported API v1 instead of v2.
API v1: from maya import OpenMaya
API v2: from maya.api import OpenMaya
In API v2 I can use MTimeArray.__setitem__() without any problem. Thanks to the support team.