Why does the apply_pose operater not work when invoked from a script?
If an operator is called from the UI it is implicitly given a context which depends on the area the operator has been called from and contains specific information about that area.

In your case you are calling an operator from the text area which is supposed to be called from the properties area. It is given the wrong context and can not retrieve the information it needs from it.

See


How to override a context
An overview of the different contexts and their contents 
Gotcha Operators


In the text context
there is only edit_text available. The global context does not contain information about the active object and the selected pose bones, neither. But the screen context does.

However here is an example how to override the context in this case:

import bpy
#get your armature
obj = bpy.data.objects['Armature']
selected_bones = [pose_bone for pose_bone in obj.pose.bones if pose_bone.bone.select]

context = {}
context['scene'] = bpy.context.scene
context['active_object'] = obj
context['selected_pose_bones'] = selected_bones

bpy.ops.poselib.apply_pose(context, pose_index=1)


This is the minimal content which is required to run the operator. It still gives warnings. Messages about window, screen, area, region not being found often can be ignored. You might pass None for these entrys to suppress the warnings.

Example: How to refer to an area in the same screen where the operator is being run from

context['window'] = context.window
context['screen'] = context.screen
for area in context.screen.areas:
    if area.type == 'PROPERTIES':
         break
context['area'] = area
context['region'] = area.regions[1]
context['space_data'] = area.spaces[0]